Document markup and improve choice tags
This commit is contained in:
@@ -7,7 +7,7 @@ import { BaseModule } from './base-module.js';
|
||||
class MarkupParserModule extends BaseModule {
|
||||
constructor() {
|
||||
super('markup-parser', 'Markup Parser');
|
||||
this.dependencies = [];
|
||||
this.dependencies = ['game-config'];
|
||||
this.assetRoots = {
|
||||
images: '/images/',
|
||||
music: '/music/',
|
||||
@@ -24,6 +24,9 @@ class MarkupParserModule extends BaseModule {
|
||||
'markdownToHtml',
|
||||
'markdownToPlainText',
|
||||
'smartypants',
|
||||
'applyLocaleTypography',
|
||||
'getTypographyLocale',
|
||||
'normalizeDialogueQuotes',
|
||||
'escapeHtml',
|
||||
'normalizeParagraph',
|
||||
'buildParagraphBlock',
|
||||
@@ -225,12 +228,38 @@ class MarkupParserModule extends BaseModule {
|
||||
}
|
||||
|
||||
smartypants(text) {
|
||||
return String(text)
|
||||
const result = String(text)
|
||||
.replace(/---/g, '\u2014')
|
||||
.replace(/--/g, '\u2013')
|
||||
.replace(/\.\.\./g, '\u2026')
|
||||
.replace(/(^|[\s([{\u2014])"([^"]*)"/g, '$1\u201c$2\u201d')
|
||||
.replace(/(^|[\s([{\u2014])'([^']*)'/g, '$1\u2018$2\u2019');
|
||||
|
||||
return this.applyLocaleTypography(result);
|
||||
}
|
||||
|
||||
applyLocaleTypography(text) {
|
||||
const locale = this.getTypographyLocale();
|
||||
if (locale.startsWith('de')) {
|
||||
return this.normalizeDialogueQuotes(text);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
getTypographyLocale() {
|
||||
const gameConfig = this.getModule('game-config') || window.GameConfig;
|
||||
const locale = gameConfig?.getLocale?.()
|
||||
|| gameConfig?.getConfig?.()?.metadata?.language
|
||||
|| 'en_US';
|
||||
|
||||
return String(locale).trim().toLowerCase().replace('_', '-');
|
||||
}
|
||||
|
||||
normalizeDialogueQuotes(text) {
|
||||
return String(text || '')
|
||||
.replace(/&(ldquo|bdquo|laquo|raquo);([^&\n]+?)&(rdquo|ldquo|laquo|raquo);/gi, '»$2«')
|
||||
.replace(/["\u201c\u201e\u201d\u00ab\u00bb]([^"\u201c\u201e\u201d\u00ab\u00bb\n]+?)["\u201c\u201d\u201e\u00ab\u00bb]/g, '»$1«');
|
||||
}
|
||||
|
||||
escapeHtml(text) {
|
||||
|
||||
Reference in New Issue
Block a user