Skip to content

Improve extraction of section texts from Markdown headings #2

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

Closed
davorpa opened this issue Sep 10, 2022 · 0 comments · Fixed by #4
Closed

Improve extraction of section texts from Markdown headings #2

davorpa opened this issue Sep 10, 2022 · 0 comments · Fixed by #4

Comments

@davorpa
Copy link
Member

davorpa commented Sep 10, 2022

According to current code...

if (item.type == "heading") {
if (item.depth == 3) {
// Heading is an h3
currentDepth = 3;
let newSection = {
section: item.children[0].value, // Get the name of the section
entries: [],
subsections: [],
};
sections.push(newSection); // Push the section to the output array
} else if (item.depth == 4) {
// Heading is an h4
currentDepth = 4;
let newSubsection = {
section: item.children[0].value, // Get the name of the subsection
entries: [],
};
sections[sections.length - 1].subsections.push(newSubsection); // Add to subsection array of most recent h3
}
} else if (item.type == "list") {
item.children.forEach((listItem) => {

it seems that the parser not supports HTML anchor aliases neither Markdown syntax. It takes for granted that childrens[0] will be plain text.

image
image

It's necesary make a ES6 Array.reduce of the heading item.children taking into account all cases in order to rebuild the desired text. Cases type:

  • html, link: ignore record. maybe an anchor alias or a back to top/upper section link
  • text: append value
  • emphasis: append children values wrapping between _ (italic Markdown tokens)
  • strong: append children values wrapping between ** (bold Markdown tokens)
  • ...
    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant