From 9ef6c68882d20c31fa3e9a291e260fef50722297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 12 Apr 2019 09:18:26 +0200 Subject: [PATCH] Class diagrams --- README.md | 36 ++++++++++++++++++------------------ parse.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e042b67..2b81012 100644 --- a/README.md +++ b/README.md @@ -1534,28 +1534,28 @@ class MyClass(metaclass=MyMetaClass): #### Type diagram ('abc' is a str, str is a type, ...): ```text -┏━━━━━━━━━┯━━━━━━━━━━━━━┓ -┃ classes │ metaclasses ┃ -┠─────────┼─────────────┨ -┃ MyClass → MyMetaClass ┃ -┃ │ ↓ ┃ -┃ object ───→ type ←╮ ┃ -┃ │ ↑ ╰───╯ ┃ -┃ str ───────╯ ┃ -┗━━━━━━━━━┷━━━━━━━━━━━━━┛ ++---------+-------------+ +| classes | metaclasses | ++---------|-------------| +| MyClass > MyMetaClass | +| | v | +| object ---> type <+ | +| | ^ +---+ | +| str -------+ | ++---------+-------------+ ``` #### Inheritance diagram (str inherits from object, ...): ```text -┏━━━━━━━━━┯━━━━━━━━━━━━━┓ -┃ classes │ metaclasses ┃ -┠─────────┼─────────────┨ -┃ MyClass │ MyMetaClass ┃ -┃ ↓ │ ↓ ┃ -┃ object ←─── type ┃ -┃ ↑ │ ┃ -┃ str │ ┃ -┗━━━━━━━━━┷━━━━━━━━━━━━━┛ ++---------+-------------+ +| classes | metaclasses | ++---------|-------------| +| MyClass | MyMetaClass | +| v | v | +| object <--- type | +| ^ | | +| str | | ++---------+-------------+ ``` diff --git a/parse.js b/parse.js index 9ef0ccb..e0c09e7 100755 --- a/parse.js +++ b/parse.js @@ -30,6 +30,50 @@ const TOC = '}\n' + '\n'; +const DIAGRAM_1_A = + '+---------+-------------+\n' + + '| classes | metaclasses |\n' + + '+---------|-------------|\n' + + '| MyClass > MyMetaClass |\n' + + '| | v |\n' + + '| object ---> type <+ |\n' + + '| | ^ +---+ |\n' + + '| str -------+ |\n' + + '+---------+-------------+\n'; + +const DIAGRAM_1_B = + '┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' + + '┃ classes │ metaclasses ┃\n' + + '┠─────────┼─────────────┨\n' + + '┃ MyClass → MyMetaClass ┃\n' + + '┃ │ ↓ ┃\n' + + '┃ object ───→ type ←╮ ┃\n' + + '┃ │ ↑ ╰───╯ ┃\n' + + '┃ str ───────╯ ┃\n' + + '┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n'; + +const DIAGRAM_2_A = + '+---------+-------------+\n' + + '| classes | metaclasses |\n' + + '+---------|-------------|\n' + + '| MyClass | MyMetaClass |\n' + + '| v | v |\n' + + '| object <--- type |\n' + + '| ^ | |\n' + + '| str | |\n' + + '+---------+-------------+\n'; + +const DIAGRAM_2_B = + '┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' + + '┃ classes │ metaclasses ┃\n' + + '┠─────────┼─────────────┨\n' + + '┃ MyClass │ MyMetaClass ┃\n' + + '┃ ↓ │ ↓ ┃\n' + + '┃ object ←─── type ┃\n' + + '┃ ↑ │ ┃\n' + + '┃ str │ ┃\n' + + '┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n'; + function main() { const html = getMd(); @@ -50,11 +94,17 @@ function initDom(html) { } function getMd() { - const readme = readFile('README.md'); + var readme = readFile('README.md'); + readme = switchClassDiagrams(readme); const converter = new showdown.Converter(); return converter.makeHtml(readme); } +function switchClassDiagrams(readme) { + readme = readme.replace(DIAGRAM_1_A, DIAGRAM_1_B) + return readme.replace(DIAGRAM_2_A, DIAGRAM_2_B) +} + function modifyPage() { removeOrigToc(); addToc();