Skip to content

Commit fbc6e26

Browse files
committed
Added simple web parser
1 parent 34b63a4 commit fbc6e26

6 files changed

Lines changed: 95 additions & 11 deletions

File tree

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
]
5+
}

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ ProtoML is a lightweight, declarative markup language designed for writing and s
130130
`protoparser` is the command-line tool for parsing `.pml` files (ProtoML) and converting them into structured formats such as JSON, HTML, PDF and more.
131131
**The parser currently only support HTML rendering.** The other formats are planned for future releases.
132132

133+
## Basic web parser
134+
135+
The web parser allows you to directly write and simply parse ProtoML code in your browser. It does not fully support all features of the parser.
136+
Additionally, CSS is not supported within the web parser.
137+
138+
To start using the web parser, simply open the `web/index.html`
139+
To rebuild the parser bundle, run `npm run build:web` in the root directory of the project.
140+
To run a webserver directly use `npm run dev` which starts a `serve` command on port 3000.
141+
133142
### Basic Usage
134143

135144
```bash
@@ -142,12 +151,6 @@ protparser [options] [filename] [format]
142151
protoparser -vvv -output=myfile MeetingYesterday.pml html
143152
```
144153

145-
### Local development
146-
147-
- Clone the repository
148-
- Make your changes
149-
- Run `npm run build:exe` to build linux and windows executables or simply run `npm uninstall -g protoparser && npm install -g .` to install your local version globally.
150-
151154
### Output
152155

153156
```plaintext
@@ -176,6 +179,12 @@ protoparser -vvv -output=myfile MeetingYesterday.pml html
176179
| `-config=PATH` | Use external config for rendering/export |
177180
| `--help` | Show CLI help |
178181

182+
### Local development
183+
184+
- Clone the repository
185+
- Make your changes
186+
- Run `npm run build:exe` to build linux and windows executables or simply run `npm uninstall -g protoparser && npm install -g .` to install your local version globally.
187+
179188
### Supported formats
180189

181190
- `json`

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "protoml-parser",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "ProtoML is a lightweight, declarative markup language designed for writing and structuring meeting protocols, notes and task lists in a human-readable and machine-parseable format.",
55
"keywords": [
66
"protoml",
@@ -18,7 +18,9 @@
1818
},
1919
"scripts": {
2020
"test": "echo \"Error: no test specified\" && exit 1",
21-
"build:exe": "pkg . --out-path dist"
21+
"build:exe": "pkg . --out-path dist",
22+
"build:web": "cd web && browserify parser-web-entry.js --standalone ProtoParser > parser.bundle.js",
23+
"dev": "serve web"
2224
},
2325
"repository": {
2426
"type": "git",
@@ -41,6 +43,10 @@
4143
},
4244
"homepage": "https://github.com/Ente/protoml-parser#readme",
4345
"devDependencies": {
44-
"pkg": "^5.8.1"
46+
"@babel/core": "^7.27.1",
47+
"@babel/preset-env": "^7.27.2",
48+
"pkg": "^5.8.1",
49+
"serve": "^14.0.1",
50+
"browserify": "^17.0.0"
4551
}
4652
}

src/renders/html.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const fs = require("fs");
22
const path = require("path");
33

4-
function loadTheme(themeName) {
4+
function loadTheme(themeName, skip = 0) {
5+
if (skip) {
6+
return "";
7+
}
58
const themePath = path.join(
69
__dirname,
710
"./themes",
@@ -33,7 +36,7 @@ function escape(text) {
3336
}
3437

3538
function renderHTML(ast, options = {}) {
36-
const css = loadTheme(options.theme);
39+
const css = loadTheme(options.theme, options.skipTheme);
3740

3841
const html = [];
3942

web/index.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<title>ProtoML Viewer</title>
7+
8+
9+
</head>
10+
11+
<body>
12+
<h1>ProtoML Viewer</h1>
13+
<p>The viewer heavily differs from the parser as not all styles are supported.</p>
14+
<textarea id="input" rows="10" cols="80">@date:21.05.2025
15+
@notes
16+
- Some note
17+
</textarea><br />
18+
<button onclick="render()">Render</button>
19+
<iframe id="preview" style="width:100%; height:300px;"></iframe>
20+
<button id="download">Download</button>
21+
22+
</body>
23+
<script src="parser.bundle.js"></script>
24+
<script>
25+
function render() {
26+
const input = document.getElementById("input").value;
27+
const html = ProtoParser.parseTextToHTML(input);
28+
document.getElementById("preview").srcdoc = html;
29+
}
30+
31+
document.getElementById("download").addEventListener("click", () => {
32+
const content = input.value;
33+
downloadFile(content, "protocol.pml", "text/plain");
34+
});
35+
36+
function downloadFile(content, filename, mime) {
37+
const blob = new Blob([content], { type: mime });
38+
const a = document.createElement("a");
39+
a.href = URL.createObjectURL(blob);
40+
a.download = filename;
41+
a.click();
42+
setTimeout(() => URL.revokeObjectURL(a.href), 500);
43+
}
44+
</script>
45+
46+
</html>

web/parser-web-entry.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { tokenize } = require('../src/core/tokenizer.js');
2+
const { parseBlocks } = require('../src/core/blockParser.js');
3+
const { resolveReferences } = require('../src/core/referenceLinker.js');
4+
const { parseInline } = require('../src/core/inlineParser.js');
5+
const renderHTML = require('../src/renders/html.js');
6+
7+
function parseTextToHTML(source) {
8+
const tokens = tokenize(source);
9+
let ast = parseBlocks(tokens);
10+
ast = resolveReferences(ast);
11+
ast = parseInline(ast);
12+
return renderHTML(ast, { skipTheme: 1});
13+
}
14+
15+
module.exports = { parseTextToHTML };

0 commit comments

Comments
 (0)