Skip to content

Commit 4d2f094

Browse files
committed
Add processing of HTML blocks and links in the compatibility mode with AkURQ
1 parent 8f781f4 commit 4d2f094

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

css/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ div.clearfix + div.text, #textfield div.text:first-child {
121121
margin-right: 10px;
122122
}
123123

124+
.akurq_html p {
125+
display: block;
126+
margin: 10px 0;
127+
}
128+
124129

125130
/** footer */
126131

docs/urql.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,21 @@ <h3>Примеры</h3>
476476
<h3>Режимы urq_mode</h3>
477477
<p>Режим urq_mode можно задать как из кода игры через соответствующую переменную, так и при помощи <a href="#файл_manifest.json">файла manifest.json</a>.</p>
478478
<h5><mark>urq_mode="ripurq"</mark></h5>
479-
<p><mark>;</mark> - однострочный комментарий</p>
480479
<p>системные переменные вида <mark>count_метка</mark> теперь выглядят как просто "метка", т.е. count_ опускается</p>
481480
<p>очищаются кнопки при переходе <mark>goto</mark></p>
482-
<p>нет системных переменных <mark>common</mark> и <mark>date</mark></p>
483481
<p>Символы разметки HTML экранируются и отображаются вместе с остальным текстом</p>
482+
<p>нет системных переменных <mark>common</mark> и <mark>date</mark></p>
483+
<p><mark>;</mark> - однострочный комментарий</p>
484484
<h5><mark>urq_mode="dosurq"</mark></h5>
485485
<p>меняет цвет фона на черный</p>
486-
<p><mark>;</mark> - однострочный комментарий</p>
487-
<p>нет системной переменной <mark>date</mark></p>
488486
<p>Символы разметки HTML экранируются и отображаются вместе с остальным текстом</p>
489-
<h5><mark>urq_mode="akurq"</mark></h5>
487+
<p>нет системной переменной <mark>date</mark></p>
490488
<p><mark>;</mark> - однострочный комментарий</p>
489+
<h5><mark>urq_mode="akurq"</mark></h5>
490+
<p>Обрабатывается разметка HTML в блоках <mark>&lt;html&gt;...&lt;/html&gt;</mark></p>
491+
<p>Обрабатываются ссылки перехода на метки вида <mark>&lt;a href="btn:метка"&gt;название&lt;/a&gt;</mark></p>
491492
<p>нет системной переменной <mark>date</mark></p>
493+
<p><mark>;</mark> - однострочный комментарий</p>
492494
</div>
493495

494496
<div id="плагины">

js/Quest.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,42 @@ function Quest(text) {
6161
text = text.replace(/\/\*[\s\S.]+?\*\//g, '');
6262
// Trim leading whitespaces from each line
6363
text = text.replace(/^\s+/gm, '');
64+
// Convert specific AkURQ constructs to UrqW constructs
65+
if (mode === 'akurq') {
66+
text = preparserForAkURQ(text);
67+
}
6468
// Split the text into an array of lines
6569
this.quest = text.split(/[\n\r]+/);
6670

6771
/**
6872
* @type {string} MurmurHash3 hash of the quest source code
6973
*/
7074
this.hash = murmurhash3_32(text);
75+
76+
/**
77+
* @type {string} URQL code with possible AkURQ-specific constructs
78+
*/
79+
function preparserForAkURQ(code) {
80+
// Regular expression for finding HTML blocks
81+
var htmlPattern = /<html>[\s\S]*?<\/html>/gi;
82+
// Perform a replacement
83+
code = code.replace(htmlPattern, (match) => {
84+
// Delete the <html> and </html> tags
85+
var content = match.replace(/^<html>\s*|\s*<\/html>$/gi, '');
86+
// Delete single-line comments from semicolon to end of line
87+
content = content.replace(/;.*$/gm, '');
88+
// Replace line breaks with spaces
89+
content = content.replace(/[\r\n]+/g, ' ');
90+
// Trim spaces at the ends
91+
content = content.trim();
92+
// Replace AkURQ links with UrqW links
93+
// (e.g., replace '<a href="btn:label">name</a>' with '[[name|label]]')
94+
content = content.replace(/<a\s+href="btn:([^"]+)"\s*>\s*([^<]+?)\s*<\/a>/gi, '[[$2|$1]]');
95+
// Forming the final line for UrqW
96+
return 'pln <div class="akurq_html">' + content + '</div>\n';
97+
});
98+
return code;
99+
}
71100
}
72101

73102

0 commit comments

Comments
 (0)