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

API v2 #243

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/target

node_modules
dist

config.toml
mappers.toml
!.cargo/config.toml
Expand Down
15 changes: 8 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"typescript": {
"indentWidth": 2,
"semiColons": "asi",
"quoteStyle": "preferSingle",
"useBraces": "always"
},
"json": {
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"**/tests"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.93.0.wasm",
"https://plugins.dprint.dev/json-0.19.4.wasm"
]
}
52 changes: 26 additions & 26 deletions parse-rfd/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,48 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

let Asciidoctor = require("@asciidoctor/core");
let convert = require("html-to-text").convert;
let Asciidoctor = require('@asciidoctor/core')
let convert = require('html-to-text').convert

const asciidoc = Asciidoctor();
const asciidoc = Asciidoctor()

const parse = (content) => {
const doc = asciidoc.load(content);
const doc = asciidoc.load(content)

const sections = doc
.getSections()
.map((section) => formatSection(section, content))
.reduce((acc, prev) => [...acc, ...prev], []);
.reduce((acc, prev) => [...acc, ...prev], [])

const title = doc.getTitle()

return {
title: (title || "")
.replace("RFD", "")
.replace("# ", "")
.replace("= ", "")
title: (title || '')
.replace('RFD', '')
.replace('# ', '')
.replace('= ', '')
.trim()
.split(' ')
.slice(1)
.join(' '),
sections
};
};
sections,
}
}

const formatSection = (section, content) => {
const formattedSections = [];
const formattedSections = []
for (const s of section.getSections()) {
formattedSections.push(...formatSection(s, content));
formattedSections.push(...formatSection(s, content))
}
const parentSections = [];
let level = section.getLevel() - 1;
let currSection = section.getParent();
const parentSections = []
let level = section.getLevel() - 1
let currSection = section.getParent()

while (level-- && currSection) {
if (typeof currSection.getName === 'function') {
parentSections.push(currSection.getName());
parentSections.push(currSection.getName())
}
currSection = currSection.getParent();
currSection = currSection.getParent()
}

return [
Expand All @@ -53,15 +53,15 @@ const formatSection = (section, content) => {
content: convert(
section
.getBlocks()
.filter((block) => block.context !== "section")
.filter((block) => block.context !== 'section')
.map((block) => block.convert())
.join("")
.join(''),
),
parents: parentSections
parents: parentSections,
},
...formattedSections,
];
};
]
}

let content = require("fs").readFileSync(0, 'utf-8');
console.log(JSON.stringify(parse(content)))
let content = require('fs').readFileSync(0, 'utf-8')
console.log(JSON.stringify(parse(content)))
Loading
Loading