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

fix: Numbered Lists not incremental #58

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions parser/__tests__/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ describe("parseParagraph", () => {
...paragraph,
bullet: { nestingLevel: 1, listId: "list-id" },
};
documentContext.orderedList = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add some more test cases for:

  • No orderedList set (should use the default)
  • More than one item (so the number goes up)
  • Multiple numbered lists in the same document
  • Multiple lists, both numbered and unnumbered in the same document

Copy link
Member Author

Choose a reason for hiding this comment

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

noted

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm having troubles getting the testsuite to write more than 1 line. adding \n makes the second line be part of the same Item, on a new line, padded.
Could you please give me an example test which has more than 1 item?

Copy link
Collaborator

Choose a reason for hiding this comment

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

try using whatever gdocs returns for the doc that is causing this issue (after changing it to not be so verbose, of course)

Copy link

Choose a reason for hiding this comment

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

Hey @buddy-web3 , are you still working on this PR?
As far as I can tell, @mruwnik 's requested test cases haven't yet been added. Is this right? If so, happy to try to add the requested cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I reckon you can take this over

documentContext.lists["list-id"].listProperties.nestingLevels[1].glyphType =
"DECIMAL";
const result = parseParagraph(documentContext)(listItem);
Expand Down
10 changes: 4 additions & 6 deletions parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const parseDoc = async (doc, answer) => {
inlineObjects: doc.inlineObjects,
lists: doc.lists || {},
suggestions: new Map(), // Accumulators for the count and total text length of all suggestions
orderedList: 1,
};
const { paragraphs, relatedAnswerDocIDs, alternativePhrasings, glossary } =
extractDocParts(doc);
Expand All @@ -105,7 +106,6 @@ export const parseDoc = async (doc, answer) => {
}

const body = paragraphs.map(parseParagraph(documentContext)).join("\n\n");

const footnotes = extractFootnotes(documentContext, doc);

const md = body + "\n\n" + footnotes;
Expand Down Expand Up @@ -241,6 +241,7 @@ export const parseParagraph = (documentContext) => (paragraph) => {
const listID = pb.listId;
const list = documentContext.lists[listID];
const currentLevel = list.listProperties.nestingLevels[nestingLevel];
const orderedList = documentContext.orderedList;

// This check is ugly as sin, but necessary because GDocs doesn't actually clearly say "this is an [un]ordered list" anywhere
// I think this is because internally, all lists are ordered and it just only sometimes uses glyphs which represent that
Expand All @@ -249,12 +250,9 @@ export const parseParagraph = (documentContext) => (paragraph) => {
currentLevel.hasOwnProperty("glyphType") &&
currentLevel.glyphType !== "GLYPH_TYPE_UNSPECIFIED";

// Please forgive me for always using 1. as the sequence number on list items
// It's sorta hard to count them properly so I'm depending on markdown renderers doing the heavy lifting for me.
// Which, in fairness, they're supposed to.
itemMarker = isOrdered ? "1. " : "- ";
itemMarker = isOrdered ? orderedList + ". " || "1. " : "- ";
leadingSpace = new Array(nestingLevel).fill(" ").join("");

documentContext.orderedList++;
buddy-web3 marked this conversation as resolved.
Show resolved Hide resolved
return (
leadingSpace +
itemMarker +
Expand Down