Skip to content

Commit

Permalink
Include DOMPurify in the demo bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
tushuhei committed Jul 31, 2024
1 parent 57f5581 commit 1d4a081
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
18 changes: 15 additions & 3 deletions demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"author": "Shuhei Iitsuka",
"license": "Apache-2.0",
"dependencies": {
"budoux": "file:../javascript"
"budoux": "file:../javascript",
"dompurify": "^3.1.6"
},
"devDependencies": {
"@types/dompurify": "^3.0.3",
Expand Down
12 changes: 3 additions & 9 deletions demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import DOMPurify from 'dompurify';
import { loadDefaultJapaneseParser, loadDefaultSimplifiedChineseParser, loadDefaultTraditionalChineseParser, loadDefaultThaiParser } from 'budoux';

const parsers = new Map([
Expand All @@ -39,19 +40,12 @@ worker.onmessage = (e: MessageEvent) => {
console.log('response from worker:', e);
};

declare global {
interface Window {
DOMPurify: {
sanitize: (value: string) => string;
}
}
}

/**
* Runs the BudouX model to process the input text and render the processed HTML.
*/
const run = () => {
outputContainerElement.innerHTML = window.DOMPurify.sanitize(inputTextElement.value);
outputContainerElement.innerHTML = DOMPurify.sanitize(inputTextElement.value);
const model = modelSelectElement.value;
worker.postMessage({'sentence': outputContainerElement.textContent, 'model': model});
const parser = parsers.get(model);
Expand All @@ -60,7 +54,7 @@ const run = () => {
outputContainerElement.style.fontSize = `${fontSizeElement.value}rem`;
const renderWithBR = brCheckElement.checked;
if (renderWithBR) {
outputContainerElement.innerHTML = window.DOMPurify.sanitize(
outputContainerElement.innerHTML = DOMPurify.sanitize(
outputContainerElement.innerHTML.replace(/\u200b/g, '<br>'));
}
};
Expand Down
1 change: 0 additions & 1 deletion demo/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ <h1>BudouX 🍇</h1>
</div>
<p id="output"></p>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.3/purify.min.js"></script>
<script src="./app.js"></script>
</body>
</html>

0 comments on commit 1d4a081

Please sign in to comment.