googleworkspace / google-docs-hast

Converts the JSON representation of a Google Docs document into an HTML abstract syntax tree (HAST).
Apache License 2.0
27 stars 12 forks source link

fix: undefined glyphType and nested lists #5

Closed Yankie closed 1 year ago

Yankie commented 1 year ago

It seems like GoogleDocs API does not set glyphType for unordered lists

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

jpoehnelt commented 1 year ago

Probably need to regenerate some of the snapshots which were probably incorrect. I think npm test -- --update should do that.

Yankie commented 1 year ago

Probably need to regenerate some of the snapshots which were probably incorrect. I think npm test -- --update should do that.

Moreover, it seems your reduce func in transform at src/hast/index.ts:93 joins all list items in one list later at lines 123-144... But there should be 2 lists - ul with 1 nested ul and ol with 1 nested ol... May be you could distinguish them by bullet value

I'm not sure yet how and where it should be treated - at hast level or later at html, but i've just started :)

Yankie commented 1 year ago

Since I'm new to TS, could you please help me with this? Thanx in advance!

...
// get last child Element from element's children
const getLastElementChild = (el: Element): Element => {
  return el.children.filter((e) => {e.type === "element"}).at(-1);
};
...

I've got error about Type 'ElementContent' is not assignable to type 'Element':

src/hast/index.ts:106:3 - error TS2322: Type 'ElementContent' is not assignable to type 'Element'.
  Type 'Comment' is missing the following properties from type 'Element': tagName, children

106   return el.children.filter((e) => {e.type === "element"}).slice(-1)[0];
Yankie commented 1 year ago

Since I'm new to TS, could you please help me with this? Thanx in advance!

...
// get last child Element from element's children
const getLastElementChild = (el: Element): Element => {
  return el.children.filter((e) => {e.type === "element"}).at(-1);
};
...

I've got error about Type 'ElementContent' is not assignable to type 'Element':

src/hast/index.ts:106:3 - error TS2322: Type 'ElementContent' is not assignable to type 'Element'.
  Type 'Comment' is missing the following properties from type 'Element': tagName, children

106   return el.children.filter((e) => {e.type === "element"}).slice(-1)[0];

Nevermind, I've figured it out!

// get last child Element from element's children
const getLastElementChild = (el: Element): Element => {
  return el.children.filter((e) => {e.type === "element"}).at(-1) as Element;
};
Yankie commented 1 year ago

Tomorrow, will fix case when list levels of current and prev elements diff by 2 and more

jpoehnelt commented 1 year ago

Thanks for the work here. Tests pass now but sounds like there is another test case from you last comment?

Yankie commented 1 year ago

@jpoehnelt i'm done!

Yankie commented 1 year ago

Here is my test document: https://docs.google.com/document/d/10foD4QkNSSK48o5_1IJabwZ3twpKC4ZUTKo0VaSMYFE

jpoehnelt commented 1 year ago

@Yankie do you mind sharing your use case for this library. You can email me at jpoehnelt@google.com. Thanks! Looks like 1.0.2 is available on NPM now.

Yankie commented 1 year ago

Sure! Thanks!