Skip to content

How to remove HTML content but keep line breaks from <br/> tags? #576

Closed Answered by ChrisMBarr
ChrisMBarr asked this question in Q&A
Discussion options

You must be logged in to vote

As a follow up I wanted to share my solution. Please advise if there is a better way to handle this.

I used these options:

{
  ignoreAttributes: false,
  ignoreDeclaration: true,
  attributeNamePrefix: '',
  parseAttributeValue: true,
  stopNodes: ['verse.lines'],
  tagValueProcessor: (_tagName, tagValue, jPath): string | null => {
    return jPath === 'verse.lines' ? tagValue : null;
  },
}

And after parsing, that will now always return a string of text and HTML/XML nodes inside of each <lines> node, which I process with the below method.

private convertHtmlLineBreaksAndStripTags(str: string): string {
  return (
    str
      //replace correctly and incorrectly formatted <br> </br> and …

Replies: 5 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by ChrisMBarr
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ChrisMBarr
Comment options

@ChrisMBarr
Comment options

Comment options

You must be logged in to vote
1 reply
@ChrisMBarr
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants