Skip to content

Commit 449ac1d

Browse files
committed
Add html beautify
1 parent 67933b0 commit 449ac1d

File tree

10 files changed

+568
-18
lines changed

10 files changed

+568
-18
lines changed

dist/html-beautify.1.15.4.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

mobile.html

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

package-lock.json

Lines changed: 523 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"cssnano": "^7.1.1",
4545
"diff": "^5.2.0",
4646
"eslint": "^9.37.0",
47+
"eyo-kernel": "^3.0.2",
48+
"globals": "^16.4.0",
49+
"js-beautify": "^1.15.4",
4750
"lyam": "^3.2.1",
4851
"postcss": "^8.5.6",
4952
"postcss-import": "^16.1.1",
@@ -52,19 +55,19 @@
5255
"rollup": "^4.52.4",
5356
"rollup-plugin-css-only": "^4.5.5",
5457
"rollup-plugin-postcss": "^4.0.2",
58+
"terser": "^5.44.0",
5559
"throttle-debounce": "^5.0.2",
5660
"tslib": "^2.8.1",
5761
"typescript": "^5.9.3",
58-
"typograf": "^7.5.0",
5962
"typescript-eslint": "^8.45.0",
60-
"globals": "^16.4.0",
61-
"eyo-kernel": "^3.0.2"
63+
"typograf": "^7.5.0"
6264
},
6365
"scripts": {
6466
"copy:dict": "cp ./node_modules/eyo-kernel/dictionary/safe.txt ./dist/eyo.txt",
67+
"copy:html-beautify": "terser ./node_modules/js-beautify/js/lib/beautify-html.js > ./dist/html-beautify.1.15.4.js",
6568
"test": "npm run eslint && npm run typecheck",
6669
"eslint": "eslint .",
6770
"typecheck": "tsc --noEmit -p tsconfig.json",
68-
"build": "npm run copy:dict && rollup -c && node tools/index.mjs"
71+
"build": "npm run copy:dict && npm run copy:html-beautify && rollup -c && node tools/index.mjs"
6972
}
7073
}

src/components/app/app.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ import { CopyIcon } from '../copyIcon/copyIcon';
1414
import { SaveFileIcon } from '../saveFileIcon/saveFileIcon';
1515
import { ShareIcon } from '../shareIcon/shareIcon';
1616
import { isJSON, typografyJSON } from '../../helpers/json';
17+
import { isHTML } from '../../helpers/string';
1718

1819
import '../container/container';
1920
import '../table/table';
2021
import '../footer/footer';
2122

2223
import './app.css';
2324

25+
declare global {
26+
interface Window {
27+
html_beautify: (text: string) => string;
28+
}
29+
}
30+
2431
export class App {
2532
private lastText: { value: string, result: string; } = { value: '', result: ''};
2633
private isMobile = document.body.classList.contains('page_mobile');
@@ -137,7 +144,13 @@ export class App {
137144
return this.typograf.execute(text, this.getTypografSettings())
138145
});
139146
} else {
140-
return this.typograf.execute(value, this.getTypografSettings())
147+
let result = this.typograf.execute(value, this.getTypografSettings());
148+
149+
if (isHTML(result) && window.html_beautify) {
150+
result = window.html_beautify(result);
151+
}
152+
153+
return result;
141154
}
142155
}
143156

src/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ <h1 class="header__title"><span data-text-id="typograf">Типограф</span><
131131
</div>
132132
</div>
133133
</footer>
134+
<script src="/dist/html-beautify.1.15.4.js" async></script>
134135
<script>
135136
{{TYPOGRAF_SCRIPT}}
136137
</script>

src/html/mobile.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ <h1 class="header__title"><span data-text-id="typograf">Типограф</span><
8585
</div>
8686
</div>
8787
</footer>
88+
<script src="/dist/html-beautify.1.15.4.js" async></script>
8889
<script>
8990
{{TYPOGRAF_SCRIPT}}
9091
</script>

src/i18n/init.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { setI18nLang, addI18nKeysets, i18nUpdatePage, I18NLanguage } from './i18n';
2+
import { keysets } from './keysets';
3+
import { config } from '../components/app/config';
4+
import { addTypografKeysets } from './typograf';
5+
import { addTypografRules } from '../rules';
6+
7+
export function initI18n() {
8+
setI18nLang(config.language as I18NLanguage);
9+
10+
addI18nKeysets(keysets);
11+
addTypografKeysets();
12+
addTypografRules();
13+
14+
i18nUpdatePage();
15+
}

src/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import { startMetrika } from './services/metrika';
2-
import { setI18nLang, addI18nKeysets, i18nUpdatePage, I18NLanguage } from './i18n/i18n';
3-
import { keysets } from './i18n/keysets';
42
import { withInstallApp } from './helpers/withInstallApp';
53
import { App } from './components/app/app';
6-
import { config } from './components/app/config';
7-
import { addTypografKeysets } from './i18n/typograf';
8-
import { addTypografRules } from './rules';
4+
import { initI18n } from './i18n/init';
95

106
startMetrika();
117

12-
setI18nLang(config.language as I18NLanguage);
13-
addI18nKeysets(keysets);
14-
addTypografKeysets();
15-
addTypografRules();
16-
17-
i18nUpdatePage();
8+
initI18n();
189

1910
withInstallApp();
2011

0 commit comments

Comments
 (0)