Skip to content

Commit

Permalink
Add JavaScript HTMLProcessor class (#58)
Browse files Browse the repository at this point in the history
This class provides extended capabilities when applying to DOM,
but with larger code size. Please see the JSDoc for more details.

* tushuhei review
  • Loading branch information
kojiishi authored Apr 25, 2022
1 parent 283bb5b commit e0c9244
Show file tree
Hide file tree
Showing 3 changed files with 698 additions and 0 deletions.
19 changes: 19 additions & 0 deletions javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ console.log(ele.outerHTML);
// <p class="budou-this" style="word-break: keep-all; overflow-wrap: break-word;">今日は<b><wbr>とても<wbr>天気</b>です。</p>
```

There is another way to apply the process to an HTML element.

```javascript
import { HTMLProcessor } from 'budoux';
const ele = document.querySelector('p.budou-this');
const applier = new HTMLProcessor(parser);
applier.applyToElement(ele);
```

The [`HTMLProcessor`] class
recognizes separate or nested paragraphs more correctly,
its output is generally more memory efficient for browsers,
and it can customize its output such as inserting a space at boundaries
which is often useful for accessibility,
but the bundle code size is larger.
Please see the JSDoc for more details.

[`HTMLProcessor`]: https://github.com/google/budoux/blob/main/javascript/src/html_processor.ts

### Loading a custom model

You can load your own custom model as follows.
Expand Down
Loading

0 comments on commit e0c9244

Please sign in to comment.