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

feat: paragraphs element enclosure. (IMPARTIAL) #57

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions parser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ const makeAnswerProcessor =
logError("Error while parsing contents", answer, err);
return false;
}
console.log(`parsed Doc: `)
console.log(parsed)
let {
md,
relatedAnswerDocIDs,
Expand Down
20 changes: 16 additions & 4 deletions parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const extractRelatedAnswerIDs = (blocks) =>
const extractAllParagraphs = (blocks) =>
blocks
.filter((block) => Object.keys(block).includes("paragraph"))
.map((b) => b.paragraph);
.map((b) => {
console.log("Extract ALL Paragraphs ", b.paragraph)
return b.paragraph
});

const extractDocParts = (doc) => {
const sectionHeaders = {
Expand Down Expand Up @@ -104,8 +107,16 @@ export const parseDoc = async (doc, answer) => {
return { md: tagContent, relatedAnswerDocIDs, alternativePhrasings };
}

const body = paragraphs.map(parseParagraph(documentContext)).join("\n\n");
console.log((">>>>>>>>>><<<<<<>>>>>>>>>>>>>>>>>>>"))
console.log("PARAGRAPHS: ")
console.log(paragraphs);
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")

const body = paragraphs.map(parseParagraph(documentContext)).join("\n\n");
console.log("--------------------------------------")
console.log("PARAGRAPHS mapped joined: ")
console.log(`${body}`);
console.log("-------------------------")
const footnotes = extractFootnotes(documentContext, doc);

const md = body + "\n\n" + footnotes;
Expand Down Expand Up @@ -223,7 +234,7 @@ export const parseParagraph = (documentContext) => (paragraph) => {

let prefix = "";
let itemMarker = "";
let leadingSpace = "";
let leadingSpace = "<div>";

// First we check if the "paragraph" is a heading, because the markdown for a heading is the first thing we need to output
if (paragraphStyleName.indexOf("HEADING_") === 0) {
Expand Down Expand Up @@ -266,7 +277,8 @@ export const parseParagraph = (documentContext) => (paragraph) => {
leadingSpace +
itemMarker +
prefix +
md.join("").replaceAll("\n", "\n" + leadingSpace)
md.join("").replaceAll("\n", "\n" + leadingSpace)+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will only work with one newline - if there are more, it will result in somwthing like:

<div>
bla bla bla
<div>ble ble ble
<div>bla bla bla
</div>

"</div>"
);
}
};
Expand Down
Loading