Skip to content
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

markdown checker #226

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e3d07a9
added source code reader
Jul 1, 2019
527c524
moved package into the tools folder
Jul 2, 2019
5cf1533
downgraded version from 1 to 0
Jul 2, 2019
1f6afca
Update tablerow object dot notation
oyilmaztekin Jul 2, 2019
de265d5
update private property
oyilmaztekin Jul 2, 2019
cde54af
Update Object dot notation
oyilmaztekin Jul 2, 2019
b01b4a5
Update test description
oyilmaztekin Jul 2, 2019
ade9c4c
Update test description
oyilmaztekin Jul 2, 2019
5204588
Update dot notation in test
oyilmaztekin Jul 2, 2019
346b29a
Update dot notation
oyilmaztekin Jul 2, 2019
2545fe6
Update destructuring assignment
oyilmaztekin Jul 2, 2019
853044f
reduced analyzeTable function
Jul 2, 2019
421e31d
Merge branch 'ozer-check-markdown' of https://github.com/oyilmaztekin…
Jul 2, 2019
a78ac0b
eslint integration
Jul 8, 2019
0601099
added new line
Jul 8, 2019
4c96e44
Merge pull request #1 from oguzzkilic/patch-1
oyilmaztekin Jul 8, 2019
a9710f7
added tested for resolver, parser and recursive test for tokenization
oyilmaztekin Jul 28, 2019
0df11c5
Merge branch 'master' of https://github.com/tc39/proposals into ozer-…
oyilmaztekin Nov 7, 2019
5325939
added test for collectLinkDefinitions.js
oyilmaztekin Nov 7, 2019
2f5a10b
added detectTables test
oyilmaztekin Nov 10, 2019
d068b15
added tables Represantation mock
oyilmaztekin Nov 11, 2019
1d15acb
fixed grammar
oyilmaztekin Nov 12, 2019
8ba807c
Merge branch 'master' into ozer-check-markdown
Sep 3, 2021
f19f819
adds handler for table head
Sep 7, 2021
829789a
removes unused function
oyilmaztekin Sep 7, 2021
cf70ee9
adds cell handler
oyilmaztekin Sep 10, 2021
b7cce4d
fixes handlers to group array by proposals
oyilmaztekin Sep 10, 2021
84d8c3d
makes refactoring on handleTables function
oyilmaztekin Sep 10, 2021
8a433ba
Merge branch 'master' into ozer-check-markdown
oyilmaztekin Sep 10, 2021
142a78b
adds doc into index.js
oyilmaztekin Sep 10, 2021
215ea12
ignores editor files
oyilmaztekin Sep 10, 2021
a14e799
removes extra spaces
oyilmaztekin Sep 10, 2021
43683bc
removes extra spaces
oyilmaztekin Sep 10, 2021
812d0ca
removes .gitignore
oyilmaztekin Sep 10, 2021
e591bdd
creates final JSON for stage1
oyilmaztekin Sep 11, 2021
6a347ee
adds some refactoring
oyilmaztekin Sep 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tools/markdown-checker/.gitignore
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/*
29 changes: 29 additions & 0 deletions tools/markdown-checker/README.md
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
3 changes: 3 additions & 0 deletions tools/markdown-checker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"stage3":"./../../../../README.md"
}
14 changes: 14 additions & 0 deletions tools/markdown-checker/index.js
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);
oyilmaztekin marked this conversation as resolved.
Show resolved Hide resolved
}

processStage3();
20 changes: 20 additions & 0 deletions tools/markdown-checker/lib/analyzer/analyzeTable.js
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.
Show resolved Hide resolved
table && table.children && detectHeader(table);
};
15 changes: 15 additions & 0 deletions tools/markdown-checker/lib/analyzer/collectLinkDefinitions.js
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.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions tools/markdown-checker/lib/analyzer/detectHeaders.js
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;
let [headerNode] = tableRow.children;
//create header template here
};
14 changes: 14 additions & 0 deletions tools/markdown-checker/lib/analyzer/detectTables.js
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.
Show resolved Hide resolved
};
192 changes: 192 additions & 0 deletions tools/markdown-checker/lib/mocks/mock.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions tools/markdown-checker/lib/parser/__tests__/readMarkdown.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const readMarkdown = require("./../readMarkdown");
const mock = require("../../mocks/mock");
const config = require("./../../../config.json");

const sourceCode = readMarkdown(config.stage3);
describe("testing parser", () => {
test("is defined", () => {
expect(sourceCode).toBeDefined();
});

test("result is matched to given mock AST", () => {
expect(sourceCode).toEqual(mock);
});
});
12 changes: 12 additions & 0 deletions tools/markdown-checker/lib/parser/parseToAst.js
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);
};
11 changes: 11 additions & 0 deletions tools/markdown-checker/lib/parser/readMarkdown.js
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");
};
15 changes: 15 additions & 0 deletions tools/markdown-checker/lib/transformer/traverser.js
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.
Show resolved Hide resolved
if (n.children) {
traverseChildren(n);
}
});

callBackLogic && callBackLogic(node);
};
Loading