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

Get the header text/value from the children #1

Closed
ggrossetie opened this issue Jan 1, 2021 · 2 comments · Fixed by #3
Closed

Get the header text/value from the children #1

ggrossetie opened this issue Jan 1, 2021 · 2 comments · Fixed by #3

Comments

@ggrossetie
Copy link
Contributor

Currently, we are using a regular expression to extract the header text from the raw value:

const headerRegExp = /^#*\s*(.*?)\s*[=-]*$/;

The issue is that the format # Title is specific to Markdown and won't work when using with an AsciiDoc document.

We can either update the regular expression to use either # or = but I think it would be better to extract the header text from the children no?

node {
  type: 'Header',
  depth: 1,
  children: [
    {
      type: 'Str',
      value: 'Document Title',
      loc: [Object],
      range: [Array],
      raw: 'Document Title'
    }
  ],
  loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 9 } },
  range: [ 0, 9 ],
  raw: '# Document Title'
}

const text = node.children
    .filter(child => child.type === 'Str')
    .map(child => child.value)
    .join(' ')
@sapegin
Copy link
Owner

sapegin commented Jan 4, 2021

That makes sense! Mind sending a pull request for that too? ;-)

@ggrossetie
Copy link
Contributor Author

As mentioned by @azu we can use textlint-util-to-string:

I always use textlint-util-to-string for extracting text content from TxtParentNode.
It picks each children nodes's value and joins these.
(It aims to pick values that are displayed as rendering result)

opendevise/textlint-plugin-asciidoc#1 (comment)

@sapegin Do you have any preference?

ggrossetie added a commit to ggrossetie/textlint-rule-title-case that referenced this issue Jan 4, 2021
@sapegin sapegin closed this as completed in #3 Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants