-
Notifications
You must be signed in to change notification settings - Fork 739
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 3 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,20 @@ | ||
| # 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 | ||
|
|
||
| # 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,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,3 @@ | ||
| { | ||
| "stage3":"./../../../../README.md" | ||
| } |
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,14 @@ | ||
| const readMarkdown = require("./lib/parser/readMarkdown"); | ||
| const parseToAST = require("./lib/parser/parseToAst"); | ||
| const collectLinkDefinitions = require("./lib/analyzer/collectLinkDefinitions"); | ||
| const tableAnalyzer = require("./lib/analyzer/analyzeTable"); | ||
| const config = require("./config.json"); | ||
|
|
||
| function processStage3({ stage3 } = config) { | ||
| const markdownStage3 = readMarkdown(stage3); | ||
| const parsedFile = parseToAST(markdownStage3); | ||
| const collectedLinkDefinitions = collectLinkDefinitions(parsedFile); | ||
| const tableStage1 = tableAnalyzer(parsedFile, collectedLinkDefinitions); | ||
| } | ||
|
|
||
| processStage3(); | ||
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,20 @@ | ||
| /** | ||
| * @todo inspect below and decide | ||
| * @template [https://jsoneditoronline.org/?id=f1ce5803d66149d5bc86d0d53ffb40c0] | ||
| * | ||
| */ | ||
|
|
||
| const detectTables = require("./detectTables"); | ||
| const detectHeader = require("./detectHeaders"); | ||
|
|
||
| /** | ||
| * | ||
| * @param {Object} node - current node of the parsed AST | ||
| * @param {Object} linkDefinitions - represents all of the link shortcuts | ||
| */ | ||
|
|
||
| module.exports = function generateTable(node, linkDefinitions) { | ||
| const table = node.children && detectTables(node); | ||
| const rows = | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| table && table["children"] && detectHeader(table); | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
| /** | ||
| * @param {Object} AST | ||
| * @returns {Object} - collected link definitions | ||
| */ | ||
| module.exports = function(AST) { | ||
| let definitions = {}; | ||
| AST.children.forEach(node => { | ||
| if (node.type === "definition") { | ||
| let label = node.label; | ||
| definitions[label] = node.url; | ||
| } | ||
| }); | ||
| return definitions; | ||
| }; | ||
|
|
||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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 traverseChildren = require("./../transformer/traverser").traverseChildren; | ||
| /** | ||
| * @param {Object} tableRow | ||
| * @returns {Object} - collected header template | ||
| */ | ||
| module.exports = function detectHeaders(tableRow) { | ||
| let cellSize = tableRow["align"].length; | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let headerNode = tableRow["children"][0]; | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //create header template here | ||
| }; | ||
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,14 @@ | ||
| /** | ||
| * @param {Object} node - Parsed markdown file an AST Object | ||
| * @returns {Array} - contains detected table nodes of the AST | ||
| */ | ||
| module.exports = function detectTables(node) { | ||
| let tables = []; | ||
| for (let i = 0; i < node.children.length; i++) { | ||
| const currentNode = node.children[i]; | ||
| if (currentNode["type"] && currentNode["type"] === "table") { | ||
| tables.push(currentNode) | ||
| } | ||
| } | ||
| return tables; | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
Large diffs are not rendered by default.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
tools/markdown-checker/lib/parser/__tests__/readMarkdown.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,13 @@ | ||
| const readMarkdown = require("./../readMarkdown"); | ||
| const mock = require("../../mocks/mock"); | ||
| const config = require("./../../../config.json"); | ||
|
|
||
| const sourceCode = readMarkdown(config["stage3"]); | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| describe("testing parser", () => { | ||
| test("should be defined ", () => { | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| expect(sourceCode).toBeDefined(); | ||
| }); | ||
| test("result should be matched to given mock AST", () => { | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| expect(sourceCode).toEqual(mock); | ||
| }); | ||
| }); | ||
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 @@ | ||
| const unified = require("unified"); | ||
| const markdown = require("remark-parse"); | ||
|
|
||
| /** | ||
| * @param {string} file - file path | ||
| * @returns {Object} - returns parsed markdown file as an AST | ||
| */ | ||
| module.exports = function(file) { | ||
| return unified() | ||
| .use(markdown) | ||
| .parse(file); | ||
| }; |
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,11 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| /** | ||
| * @param {string} markdownPath - path of the markdown file | ||
| * @returns {string} - source code of the markdown as a string | ||
| */ | ||
| module.exports = function(markdownPath) { | ||
| const resolvedPath = path.resolve(__dirname, markdownPath); | ||
| return fs.readFileSync(resolvedPath, "utf-8"); | ||
| }; |
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,15 @@ | ||
| /** | ||
| * @param {Object} Node | ||
| * @param {function} callBackLogic | ||
| */ | ||
|
|
||
| module.exports = function traverseChildren(node, callBackLogic) { | ||
| node.forEach(n => { | ||
| callBackLogic(); | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (n["children"]) { | ||
oyilmaztekin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| traverseChildren(n); | ||
| } | ||
| }); | ||
|
|
||
| callBackLogic && callBackLogic(node); | ||
| }; | ||
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.