-
Notifications
You must be signed in to change notification settings - Fork 741
markdown checker #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
oyilmaztekin
wants to merge
36
commits into
tc39:main
Choose a base branch
from
oyilmaztekin:ozer-check-markdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
markdown checker #226
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e3d07a9
added source code reader
527c524
moved package into the tools folder
5cf1533
downgraded version from 1 to 0
1f6afca
Update tablerow object dot notation
oyilmaztekin de265d5
update private property
oyilmaztekin cde54af
Update Object dot notation
oyilmaztekin b01b4a5
Update test description
oyilmaztekin ade9c4c
Update test description
oyilmaztekin 5204588
Update dot notation in test
oyilmaztekin 346b29a
Update dot notation
oyilmaztekin 2545fe6
Update destructuring assignment
oyilmaztekin 853044f
reduced analyzeTable function
421e31d
Merge branch 'ozer-check-markdown' of https://github.com/oyilmaztekin…
a78ac0b
eslint integration
0601099
added new line
4c96e44
Merge pull request #1 from oguzzkilic/patch-1
oyilmaztekin a9710f7
added tested for resolver, parser and recursive test for tokenization
oyilmaztekin 0df11c5
Merge branch 'master' of https://github.com/tc39/proposals into ozer-…
oyilmaztekin 5325939
added test for collectLinkDefinitions.js
oyilmaztekin 2f5a10b
added detectTables test
oyilmaztekin d068b15
added tables Represantation mock
oyilmaztekin 1d15acb
fixed grammar
oyilmaztekin 8ba807c
Merge branch 'master' into ozer-check-markdown
f19f819
adds handler for table head
829789a
removes unused function
oyilmaztekin cf70ee9
adds cell handler
oyilmaztekin b7cce4d
fixes handlers to group array by proposals
oyilmaztekin 84d8c3d
makes refactoring on handleTables function
oyilmaztekin 8a433ba
Merge branch 'master' into ozer-check-markdown
oyilmaztekin 142a78b
adds doc into index.js
oyilmaztekin 215ea12
ignores editor files
oyilmaztekin a14e799
removes extra spaces
oyilmaztekin 43683bc
removes extra spaces
oyilmaztekin 812d0ca
removes .gitignore
oyilmaztekin e591bdd
creates final JSON for stage1
oyilmaztekin 6a347ee
adds some refactoring
oyilmaztekin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #chunks | ||
| .DS_Store | ||
| .cache | ||
|
|
||
| #editor files | ||
| .idea/** | ||
| .vscode/** | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *_tests_* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "env": { | ||
| "node": true, | ||
| "es6": true | ||
| }, | ||
| "extends": [ | ||
| "airbnb-base" | ||
| ], | ||
| "globals": { | ||
| "Atomics": "readonly", | ||
| "SharedArrayBuffer": "readonly" | ||
| }, | ||
| "parserOptions": { | ||
| "ecmaVersion": 2018 | ||
| }, | ||
| "rules": { | ||
| "no-underscore-dangle": 0, | ||
| "import/no-extraneous-dependencies": 0, | ||
| "no-unused-vars": 0 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # environment variables | ||
| .env | ||
| .env.test | ||
| */node_modules/* | ||
| yarn.lock | ||
|
|
||
| #chunks | ||
| .DS_Store | ||
| .cache | ||
| **/.idea/** | ||
|
|
||
| # packages | ||
| node_modules/ | ||
| */node_modules/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "singleQuote": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ### MarkdownChecker | ||
| a script that generates a JSON file from the markdown which contains status of proposals. | ||
|
|
||
| #### modules | ||
| this script consist of three main stage like other compilers have | ||
| - parser | ||
| - analyzer | ||
| - transformer | ||
| - generator | ||
|
|
||
| ##### Parser | ||
| - **_readMarkdown_** : `string` | ||
| - source file will be parsed as an AST | ||
| - **_parseToAST_** : `object` | ||
| - an AST representation of the markdown | ||
|
|
||
| ##### Analyzer | ||
| - **_collectLinkDefinitions_** : `object` | ||
| - detects all link definitions declared from bottom of the markdown file and returns these definitions | ||
| - **_detectTables_** : `object` | ||
| - extracts all of the tables from the markdown and returns it as a tree | ||
| - **_detectHeaders_** : `object` | ||
| - extracts all of the row from the table nodes and returns it as a tree | ||
|
|
||
| ##### Transformer | ||
| - **_traverser_** | ||
| - takes current node as an input if it has an children nodes then applies the logic with given callback functions and returns something declared in the callback function | ||
|
|
||
| ##### Generator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| module.exports = { | ||
| stage3: './../../../../README.md', | ||
| stage1: './../../../../stage-1-proposals.md', | ||
| DEFINITION: 'definition', | ||
| TABLE: 'table', | ||
| TEXT: 'text', | ||
| ROW: 'tableRow', | ||
| CELL: 'tableCell', | ||
| HTML: 'html', | ||
| LINK: 'linkReference', | ||
| INLINE_CODE: 'inlineCode', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const readMarkdown = require('./lib/parser/readMarkdown'); | ||
| const parseToAST = require('./lib/parser/parseToAst'); | ||
| const globalData = require('./lib/data'); | ||
| const { | ||
| collectLinkDefinitions, | ||
| } = require('./lib/analyzer/collectLinkDefinitions'); | ||
| const { generateTable } = require('./lib/analyzer/analyzeTable'); | ||
| const enums = require('./enums.js'); | ||
|
|
||
| const processStage3 = (stage) => { | ||
| const activeStage = enums[stage]; | ||
| // parse stage | ||
| const markdownStage = readMarkdown(activeStage); | ||
| const parsedFile = parseToAST(markdownStage); | ||
|
|
||
| globalData.linkDefinitions = collectLinkDefinitions(parsedFile); | ||
| const tableStage1 = generateTable(parsedFile); | ||
| // TODO: write data into json file | ||
| }; | ||
|
|
||
| processStage3('stage1'); |
43 changes: 43 additions & 0 deletions
43
tools/markdown-checker/lib/analyzer/__tests__/collectLinkDefinitions.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| const readMarkdown = require('./../../parser/readMarkdown'); | ||
| const parseToAST = require('./../../parser/parseToAst'); | ||
| const { | ||
| collectLinkDefinitions, | ||
| addLinkIntoDefintions | ||
| } = require('../collectLinkDefinitions'); | ||
| const definitionNode = require('../../../mocks/definitionNode'); | ||
|
|
||
| describe('testing collectLinkDefiniton function', () => { | ||
| let parsedMarkdown; | ||
| let allLinkDefinitions; | ||
|
|
||
| beforeAll(() => { | ||
| const markdownFile = readMarkdown('../../mocks/stage3Mock.md'); | ||
| parsedMarkdown = parseToAST(markdownFile); | ||
| allLinkDefinitions = collectLinkDefinitions(parsedMarkdown); | ||
| }); | ||
|
|
||
| test('function is defined', () => { | ||
| expect(collectLinkDefinitions).toBeDefined(); | ||
| expect(typeof collectLinkDefinitions).toBe('function'); | ||
| }); | ||
|
|
||
| test('definition added into hash', () => { | ||
| const definitions = addLinkIntoDefintions({}, definitionNode); | ||
| const { label, url } = definitions; | ||
| expect(typeof definitions).toBe('object'); | ||
| expect(typeof label && typeof url).toBe('string'); | ||
| expect(label).toBe('regexp-legacy'); | ||
| expect(url).toBe('https://github.com/tc39/proposal-regexp-legacy-features'); | ||
| }); | ||
|
|
||
| test('link definitions are collected', () => { | ||
| expect(allLinkDefinitions).toBeDefined(); | ||
| expect(typeof allLinkDefinitions).toBe('object'); | ||
| expect(allLinkDefinitions['buffer-transfer']).toBe( | ||
| 'https://github.com/domenic/proposal-arraybuffer-transfer/' | ||
| ); | ||
| expect(allLinkDefinitions['private-methods']).toBe( | ||
| 'https://github.com/tc39/proposal-private-methods' | ||
| ); | ||
| }); | ||
| }); |
41 changes: 41 additions & 0 deletions
41
tools/markdown-checker/lib/analyzer/__tests__/detectTableChildren.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| const detectTables = require('../detectTables'); | ||
| const detectHeaders = require('../handleTables'); | ||
| const parsedMarkdownTree = require('../../../mocks/parsedMarkdownTree'); | ||
|
|
||
| const markdownTables = detectTables(parsedMarkdownTree); | ||
| const [child] = markdownTables; | ||
|
|
||
| describe('testing detectTables function', () => { | ||
| test('is defined', () => { | ||
| expect(detectTables).toBeDefined(); | ||
| }); | ||
| test('length is matched', () => { | ||
| expect(markdownTables.length).toEqual(2); | ||
| }); | ||
| test('has correct size of thead', () => { | ||
| expect(child.align.length).toBe(5); | ||
| }) | ||
| test('is returned table', () => { | ||
| expect(child.type).toBe('table'); | ||
| }); | ||
| test('has row and cell children', () => { | ||
| const [rowChild] = child.children; | ||
| expect(rowChild.type).toBe('tableRow'); | ||
|
|
||
| const [cellChild] = rowChild.children; | ||
| expect(cellChild.type).toBe('tableCell'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('testing detectHeaders function', () => { | ||
| let rowChild; | ||
| beforeAll(() => { | ||
| [rowChild] = child.children; | ||
| }); | ||
| test('is defined', ()=>{ | ||
| expect(detectHeaders).toBeDefined(); | ||
| }) | ||
| test('is defined', ()=>{ | ||
| rowChild; | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
|
|
||
| const detectTables = require('./detectTables'); | ||
| const handleTables = require('./handleTables'); | ||
| const { checkNodeHasChildren } = require('../utils'); | ||
| /** | ||
| * @todo inspect below and decide | ||
| * @template [https://jsoneditoronline.org/?id=f1ce5803d66149d5bc86d0d53ffb40c0] | ||
| * | ||
| */ | ||
|
|
||
| /** | ||
| * | ||
| * @param {Object} node | ||
| * @returns {Array} | ||
| */ | ||
| const extractAllTablesFromTree = (node) => { | ||
| if (checkNodeHasChildren(node)) { | ||
| return detectTables(node); | ||
| } | ||
| return []; | ||
| }; | ||
| /** | ||
| * | ||
| * @param {Object} node - current node of the parsed AST | ||
| * @param {Object} linkDefinitions - represents all of the link shortcuts | ||
| */ | ||
|
|
||
| const generateTable = (node) => { | ||
| const tables = extractAllTablesFromTree(node); | ||
| if (tables && tables.length > 0) { | ||
| tables.forEach((table) => { | ||
| if (Object.values(table).length > 0) { | ||
| const JSONTables = handleTables(table); | ||
| } | ||
| }); | ||
| } | ||
| return []; | ||
| }; | ||
|
|
||
| module.exports = { generateTable, extractAllTablesFromTree }; |
32 changes: 32 additions & 0 deletions
32
tools/markdown-checker/lib/analyzer/collectLinkDefinitions.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const { DEFINITION } = require('./../../enums.js'); | ||
|
|
||
| /** | ||
| * | ||
| * @param {Object} definitions | ||
| * @param {Object} node | ||
| * @returns {Object} | ||
| */ | ||
| function addLinkIntoDefinitions(definitions, node) { | ||
| const { label, url } = node; | ||
| // eslint-disable-next-line no-param-reassign | ||
| definitions[label] = url; | ||
| return { | ||
| label, | ||
| url, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @param {Object} AST | ||
| * @returns {Object} - collected link definitions | ||
| */ | ||
| function collectLinkDefinitions(AST) { | ||
| const definitions = {}; | ||
| AST.children.forEach((node) => { | ||
| // eslint-disable-next-line no-unused-expressions | ||
| node.type === DEFINITION && addLinkIntoDefinitions(definitions, node); | ||
| }); | ||
| return definitions; | ||
| } | ||
|
|
||
| module.exports = { collectLinkDefinitions }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const { TABLE } = require('./../../enums.js'); | ||
| /** | ||
| * @param {Object} node - Parsed markdown file an AST Object | ||
| * @returns {Array} - contains detected table nodes of the AST | ||
| */ | ||
| function detectTables(node) { | ||
| return node.children.filter(({ type }) => type === TABLE); | ||
| } | ||
|
|
||
| module.exports = detectTables; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| const { | ||
| CELL, TABLE, ROW, LINK, TEXT, | ||
| } = require('../../enums'); | ||
| const globalData = require('../data'); | ||
|
|
||
| const { tableHead } = globalData; | ||
| const { iterateAndConcatValue, handleLinkReference } = require('../utils'); | ||
|
|
||
| /** | ||
| * | ||
| * @param {Array} headNodes | ||
| * @return {handleTables} | ||
| */ | ||
| const createHead = (headNodes) => { | ||
| headNodes.forEach(({ type, children }) => { | ||
| if (type !== CELL) return null; | ||
| tableHead.push(iterateAndConcatValue(children)); | ||
| return tableHead; | ||
| }); | ||
| return tableHead; | ||
| }; | ||
|
|
||
| const handleCellLinkReference = (cell, idx) => { | ||
| const relatedHead = tableHead[idx]; | ||
| return { | ||
| [relatedHead]: handleLinkReference(cell, globalData.linkDefinitions), | ||
| }; | ||
| }; | ||
|
|
||
| const handleCellTextHTML = (cell, idx) => { | ||
| const relatedHead = tableHead[idx]; | ||
| return { | ||
| [relatedHead]: cell.value, | ||
| }; | ||
| }; | ||
|
|
||
| const handleCell = (cells, idx) => { | ||
| // FIXME: handle <br/> separated multiple champions | ||
| let result; | ||
| if (cells.length) { | ||
| cells.forEach((cell) => { | ||
| switch (cell.type) { | ||
| case LINK: | ||
| result = handleCellLinkReference(cell, idx); | ||
| return result; | ||
| case TEXT: | ||
| result = handleCellTextHTML(cell, idx); | ||
| return result; | ||
| default: | ||
| return {}; | ||
| } | ||
| }); | ||
| } | ||
| return result; | ||
| }; | ||
|
|
||
| const handleRows = (row) => { | ||
| let obj = {}; | ||
| row.forEach(({ type, children }, idx) => { | ||
| if (type !== CELL) return null; | ||
| const rowLine = handleCell(children, idx); | ||
| obj = { ...obj, ...rowLine }; | ||
| }); | ||
| return obj; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Object} table | ||
| * @returns {Array} | ||
| */ | ||
| const handleTables = ({ align: { length }, type, children }) => { | ||
| const arr = []; | ||
| if (type !== TABLE) return null; | ||
| children.forEach(({ children: tableRow, type: rowType }, idx) => { | ||
| if (rowType !== ROW) return []; | ||
| if (idx === 0) { | ||
| createHead(tableRow); | ||
| return []; | ||
| } | ||
| const row = handleRows(tableRow, length); | ||
| arr.push(row); | ||
| return arr; | ||
| }); | ||
| return arr; | ||
| }; | ||
|
|
||
| module.exports = handleTables; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module.exports = { | ||
| tableHead: [], | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.