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 all 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
1 change: 1 addition & 0 deletions tools/markdown-checker/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*_tests_*
21 changes: 21 additions & 0 deletions tools/markdown-checker/.eslintrc.json
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
}
}
21 changes: 21 additions & 0 deletions tools/markdown-checker/.gitignore
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/*
3 changes: 3 additions & 0 deletions tools/markdown-checker/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
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
12 changes: 12 additions & 0 deletions tools/markdown-checker/enums.js
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'
};
33 changes: 33 additions & 0 deletions tools/markdown-checker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const readMarkdown = require('./lib/parser/readMarkdown');
const parseToAST = require('./lib/parser/parseToAst');
const globalData = require('./lib/data');
const generateJSONFile = require('./lib/writeFile');
const {
collectLinkDefinitions,
} = require('./lib/analyzer/collectLinkDefinitions');
const { generateTable } = require('./lib/analyzer/analyzeTable');
const enums = require('./enums.js');

const processStage3 = (stage) => {
/**
* TODO: handle multiple table in readme.md
* TODO: handle "Test" columns in stage3
* TODO: handle different column lengths
*/
//

const activeStage = enums[stage];
// parse stage
const markdownStage = readMarkdown(activeStage);
const parsedFile = parseToAST(markdownStage);

globalData.linkDefinitions = collectLinkDefinitions(parsedFile);
const table = generateTable(parsedFile);
// creates JSON file
const fileName = `${stage}Table.json`;
generateJSONFile(fileName, JSON.stringify(table))
.then(_ => console.log(`The ${fileName} has been created!`))
.catch(err => console.log(`err: ${err}`));
};

processStage3('stage1');
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'
);
});
});
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;
})
})
36 changes: 36 additions & 0 deletions tools/markdown-checker/lib/analyzer/analyzeTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

const detectTables = require('./detectTables');
const handleTables = require('./handleTables');
const { checkNodeHasChildren } = require('../utils');

/**
*
* @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);
let JSONTables = [];
if (tables && tables.length > 0) {
tables.forEach((table) => {
if (Object.values(table).length > 0) {
JSONTables = handleTables(table);
}
});
}
return JSONTables;
};

module.exports = { generateTable, extractAllTablesFromTree };
32 changes: 32 additions & 0 deletions tools/markdown-checker/lib/analyzer/collectLinkDefinitions.js
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 };
10 changes: 10 additions & 0 deletions tools/markdown-checker/lib/analyzer/detectTables.js
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;
Loading