https://github.com/akrck02/markdown-docs-dev-diary
Development diary for the markdown-docs library.
https://github.com/akrck02/markdown-docs-dev-diary
dev-diary markdown parser
Last synced: 12 months ago
JSON representation
Development diary for the markdown-docs library.
- Host: GitHub
- URL: https://github.com/akrck02/markdown-docs-dev-diary
- Owner: akrck02
- Created: 2022-02-10T23:21:30.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-10T23:50:35.000Z (over 4 years ago)
- Last Synced: 2025-06-15T03:03:49.742Z (12 months ago)
- Topics: dev-diary, markdown, parser
- Homepage:
- Size: 429 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Markdown docs
A documentation parser from Markdown to HTML.
## Understanding the parsing basics.
The parsing process is probably one of the most difficult tasks to handle in the IT world.
But, ***what the hell is parsing?***
Parsing is the process of getting information with a given format and converting that input into an output formatted in a different way.
For example parsing the date formats from:
```tsx
const myDate = "20/12/2020 11:50"; // Format dd/MM/yyyy hh:mm
```
To the following date format
```tsx
const myParsedDate = "2020/12/20 11:50"; // Format yyyy/MM/dd hh:mm
```
To get the information inside the text **the code must understand the patterns living inside.**
## Converting patterns into blocks
The code will take some piece of plain text and get the information blocks inside of it. So we need some kind of program to handle that, lets call it the **tokenizer.**
Imagine the following Markdown text
```markdown
# My title here
> aside paragraph for better visibility
## Secondary title here
Normal text with **bold** and *italic*
```
The blocks inside
```html
Title: My title here
Aside: aside paragraph for better visibility
SecondaryTitle: Secondary title here
Text: Normal text with [Bold:bold] and [Italic: italic]
```
The expected HTML output for our library
```html
My title here
aside paragraph for better visibility
Secondary title here
Normal text with bold and italic
```
The **tokenizer** must understand Markup language to get the block structure inside of it, but it is not the one who must translate that structure to the HTML output, that’s why we have another worker here, the **translator.**
## Translating the Abstract Block Tree into different languages.
Yes, a translator must now the language you want it to work on, but if your parser is anyway modular, chances are that upgrading it with two or three of them wont be a problem at all.
The basic idea here is that if the abstract tree is well formed, the translator will make basic comparative operations such us:
```tsx
public String render( blocks : Block[] ) {
let output = "";
blocks.forEach(block -> {
if(block.type == "Text") {
output += "
" + render(block.children) + "
";
}
if(block.type == "Title") {
output += "" + render(block.children) + "
";
}
// --- Other type checkings ---
return block.text;
});
return output;
}
```
[Starting to code.](pages/1.StartingToCode.md)
[Coding base abstractions](pages/2.CodingBaseAbstractions.md)
[Problems](pages/3.Problems.md)