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 1 commit
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
Prev Previous commit
Next Next commit
adds handler for table head
adds some refactoring
  • Loading branch information
Özer Yılmaztekin committed Sep 7, 2021
commit f19f819df1136f9ae882eae56bc26736169e27de
1 change: 1 addition & 0 deletions tools/markdown-checker/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,7 @@ yarn.lock
#chunks
.DS_Store
.cache
**/.idea/**

# packages
node_modules/
Expand Down
3 changes: 0 additions & 3 deletions tools/markdown-checker/config.json

This file was deleted.

11 changes: 11 additions & 0 deletions tools/markdown-checker/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 1,11 @@
module.exports = {
stage3: './../../../../README.md',
stage1: './../../../../stage-1-proposals.md',
DEFINITION: 'definition',
TABLE: 'table',
TEXT: 'text',
ROW: 'tableRow',
CELL: 'tableCell',
LINK: 'linkReference',
INLINE_CODE: 'inlineCode',
};
22 changes: 12 additions & 10 deletions tools/markdown-checker/index.js
Original file line number Diff line number Diff line change
@@ -1,21 1,23 @@
const readMarkdown = require('./lib/parser/readMarkdown');
const parseToAST = require('./lib/parser/parseToAst');
const globalData = require('./lib/data');
const {
collectLinkDefinitions
collectLinkDefinitions,
} = require('./lib/analyzer/collectLinkDefinitions');
const { generateTable } = require('./lib/analyzer/analyzeTable');
const config = require('./config.json');
const { generateTable } = require('./lib/analyzer/analyzeTable');
const enums = require('./enums.js');

function processStage3({ stage3 } = config) {
const processStage3 = (stage) => {
const activeStage = enums[stage];
// parse stage
const markdownStage3 = readMarkdown(stage3);
const parsedFile = parseToAST(markdownStage3);
const markdownStage = readMarkdown(activeStage);
const parsedFile = parseToAST(markdownStage);

// transform stage
const collectedLinkDefinitions = collectLinkDefinitions(parsedFile);
const tableStage1 = generateTable(parsedFile, collectedLinkDefinitions);
globalData.linkDefinitions = collectLinkDefinitions(parsedFile);
const tableStage1 = generateTable(parsedFile);

// generate stage
}
};

processStage3();
processStage3('stage1');
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
const detectTables = require('../detectTables');
const detectHeaders = require('../detectHeaders');
const detectHeaders = require('../handleTables');
const parsedMarkdownTree = require('../../../mocks/parsedMarkdownTree');

const markdownTables = detectTables(parsedMarkdownTree);
Expand Down
39 changes: 23 additions & 16 deletions tools/markdown-checker/lib/analyzer/analyzeTable.js
Original file line number Diff line number Diff line change
@@ -1,33 1,40 @@
/**
* @todo inspect below and decide
* @template [https://jsoneditoronline.org/?id=f1ce5803d66149d5bc86d0d53ffb40c0]
*
*/

const detectTables = require('./detectTables');
const detectHeaders = require('./detectHeaders');
const checkNodeHasChildren = require('./../transformer/nodeChildrenChecker');
const handleTables = require('./handleTables');
const { checkNodeHasChildren } = require('../utils');
/**
* @todo inspect below and decide
* @template [https://jsoneditoronline.org/?id=f1ce5803d66149d5bc86d0d53ffb40c0]
*
* @param {Object} node - current node of the parsed AST
* @param {Object} linkDefinitions - represents all of the link shortcuts
*/

function generateTable(node, linkDefinitions) {
const tables = extractAllTablesFromTree(node);
const rows = tables && detectHeaders(table);
}

/**
*
* @param {Object} node
* @returns {Array}
*/
function extractAllTablesFromTree(node) {
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: 18 additions & 14 deletions tools/markdown-checker/lib/analyzer/collectLinkDefinitions.js
Original file line number Diff line number Diff line change
@@ -1,28 1,32 @@
/**
* @param {Object} AST
* @returns {Object} - collected link definitions
*/
function collectLinkDefinitions(AST) {
const definitions = {};
AST.children.forEach(node => {
node.type === 'definition' && addLinkIntoDefintions(definitions, node);
});
return definitions;
}
const { DEFINITION } = require('./../../enums.js');

/**
*
* @param {Object} definitions
* @param {Object} node
* @returns {Object}
*/
function addLinkIntoDefintions(definitions, node) {
function addLinkIntoDefinitions(definitions, node) {
const { label, url } = node;
// eslint-disable-next-line no-param-reassign
definitions[label] = url;
return {
label,
url
url,
};
}

module.exports = { collectLinkDefinitions, addLinkIntoDefintions };
/**
* @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 };
12 changes: 0 additions & 12 deletions tools/markdown-checker/lib/analyzer/detectHeaders.js

This file was deleted.

5 changes: 3 additions & 2 deletions tools/markdown-checker/lib/analyzer/detectTables.js
Original file line number Diff line number Diff line change
@@ -1,9 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');
};
return node.children.filter(({ type }) => type === TABLE);
}

module.exports = detectTables;
64 changes: 64 additions & 0 deletions tools/markdown-checker/lib/analyzer/handleTables.js
Original file line number Diff line number Diff line change
@@ -0,0 1,64 @@
const {
CELL, TABLE, ROW, LINK, TEXT,
} = require('../../enums');
const globalData = require('../data');

const { tableHead, tables } = globalData;
const { iterateAndConcatValue, handleLinkReference, concatValue } = 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 handleCell = (cells, length) => {
// FIXME: collect only related cells
if (cells.length) {
let column = {};
cells.forEach((cell, idx) => {
if (cell.type === LINK) {
const relatedHead = tableHead[idx];
column[relatedHead] = handleLinkReference(cell, globalData.linkDefinitions);
} if (cell.type === TEXT) {
const relatedHead = tableHead[idx];
column[relatedHead] = cell.value;
}
if (idx !== 0 && idx % length === 0) {
tables.push(column);
column = {};
}
});
}
return tables;
};

const handleRows = (row, length) => {
row.forEach(({ type, children }) => {
if (type !== CELL) return null;
return handleCell(children, length);
});
};

/**
* @param {Object} table
* @returns {Object} - collected header template
*/
const handleTables = ({ align: { length }, type, children }) => {
if (type !== TABLE) return null;
children.forEach(({ children: tableRow, type: rowType }, idx) => {
if (rowType !== ROW) return null;
if (idx === 0) return createHead(tableRow);
return handleRows(tableRow, length);
});
};

module.exports = handleTables;
4 changes: 4 additions & 0 deletions tools/markdown-checker/lib/data.js
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
module.exports = {
tableHead: [],
tables: [],
};
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@
const readMarkdown = require('../readMarkdown');
const config = require('./../../../config.json');
const {stage3} = require('../../../enums.js');
const parseToAST = require('./../parseToAst');
const checkHasTokenizationRererences = require('../__tests__/parserTokenTester');
const sourceCode = readMarkdown(config.stage3);
const sourceCode = readMarkdown(stage3);

describe('testing path resolver and reader', () => {
test('is defined', () => {
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions tools/markdown-checker/lib/transformer/nodeChildrenChecker.js

This file was deleted.

15 changes: 0 additions & 15 deletions tools/markdown-checker/lib/transformer/traverser.js

This file was deleted.

52 changes: 52 additions & 0 deletions tools/markdown-checker/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 1,52 @@
/**
* @param {Array} node
* @param {function} callBackLogic
*/

const traverseChildren = (node, callBackLogic) => {
node.forEach((n) => {
callBackLogic(n);
if (n.children) {
traverseChildren(n.children);
}
});

if (callBackLogic && typeof callBackLogic === 'function') callBackLogic(node);
};

/**
*
* @param {Object} node
* @returns {Boolean}
*/
const checkNodeHasChildren = node => !!node.children;

/**
*
* @param {String | Object} acc
* @param node {Object}
* @return {Buffer | any[] | string}
*/
const concatValue = (acc = '', node) => {
if (typeof acc === 'object') return acc.value node.value;
return acc node.value;
};

const iterateAndConcatValue = (children) => {
const [firstItem] = children;
if (children.length <= 1) return firstItem.value;
return children.reduce((acc, curr) => concatValue(acc, curr));
};

const handleLinkReference = ({ identifier, children }, linkDefinitions) => ({
text: iterateAndConcatValue(children),
url: linkDefinitions[identifier],
});

module.exports = {
checkNodeHasChildren,
traverseChildren,
concatValue,
iterateAndConcatValue,
handleLinkReference,
};
Loading