Skip to content

Commit be3e14d

Browse files
committed
iss1757 - Change current filters to transforms
1 parent 25fd94c commit be3e14d

9 files changed

Lines changed: 27 additions & 27 deletions

File tree

corsscripts/ascii/markdownitrules.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// Markdown-it plugin — bundled into stackascii.bundle.js via stackascii.src.js.
2-
// Edit filter behaviour in filters/*.js, then run: npm run build:bundle
2+
// Edit transform behaviour in markdownittransforms/*.js, then run: npm run build:bundle
33

4-
import boldfilter from './filters/020_boldfilter.js';
5-
import latexwrap from './filters/010_latexwrap.js';
4+
import boldfilter from './markdownittransforms/020_boldfilter.js';
5+
import latexwrap from './markdownittransforms/010_latexwrap.js';
66

7-
// Registry maps the string names used in options.filters to the actual functions.
8-
// Add new filters here after creating their file in filters/.
9-
const filterRegistry = {
7+
// Registry maps the string names used in options.transforms to the actual functions.
8+
// Add new transforms here after creating their file in markdownittransforms/.
9+
const transformRegistry = {
1010
boldfilter,
1111
latexwrap,
1212
};
1313

1414
export default function markdownitrules(mdit, options) {
1515
"use strict";
1616
options = options || {};
17-
const filters = (options.filters || '')
17+
const transforms = (options.transforms || '')
1818
.split(',')
1919
.map(s => s.trim())
2020
.filter(Boolean);
@@ -39,7 +39,7 @@ export default function markdownitrules(mdit, options) {
3939

4040
mdit.renderer.rules.asciimath_block = function(tokens, idx) {
4141
const code = tokens[idx].content;
42-
const rendered = applyFilters(code, true);
42+
const rendered = applyTransforms(code, true);
4343
if (collector) {
4444
collector.blocks.push({ type: 'asciimath_block', raw: code, rendered });
4545
}
@@ -58,7 +58,7 @@ export default function markdownitrules(mdit, options) {
5858

5959
mdit.renderer.rules.math_block = function(tokens, idx) {
6060
const code = tokens[idx].content;
61-
const rendered = applyFilters(code, false);
61+
const rendered = applyTransforms(code, false);
6262
if (collector) {
6363
collector.blocks.push({ type: 'math_block', raw: code, rendered });
6464
}
@@ -69,16 +69,16 @@ export default function markdownitrules(mdit, options) {
6969
return code.split(/\r?\n/).map(line => line.trim()).filter(line => line !== '');
7070
}
7171

72-
function applyFilters(code, isASCIIMaths) {
72+
function applyTransforms(code, isASCIIMaths) {
7373
let lines = splitBlock(code);
7474
if (isASCIIMaths) {
7575
lines = lines.map(line => window.AMparseMath(line, true));
7676
}
77-
for (const filter of filters) {
78-
if (!filterRegistry[filter]) {
79-
throw new Error(`markdownitrules: unknown filter "${filter}"`);
77+
for (const transform of transforms) {
78+
if (!transformRegistry[transform]) {
79+
throw new Error(`markdownitrules: unknown transform "${transform}"`);
8080
}
81-
lines = filterRegistry[filter](lines);
81+
lines = transformRegistry[transform](lines);
8282
}
8383
return lines.join('\n') + '\n';
8484
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

corsscripts/ascii/stackascii.bundle.js

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

corsscripts/ascii/stackascii.bundle.js.map

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

corsscripts/ascii/stackascii.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import regexall from './extractors/regexall.js';
2222

2323
const extractorlib = { finalfunction, lastexpr, lastblock, regexmatch, regexall };
2424

25-
export default function init(inputIds, filters, operations) {
25+
export default function init(inputIds, transforms, operations) {
2626
const markdownContainerId = inputIds[0];
2727
// inputIds[1..N] correspond to each parsed answer entry in order.
2828
const extractors = operations.filter(operator => operator.operation === 'extractor');
29-
const inputFilters = filters ? filters : 'latexwrap,boldfilter';
29+
const inputTransforms = transforms ? transforms : 'latexwrap,boldfilter';
3030

3131
const blockCollector = { blocks: [] };
3232

@@ -35,7 +35,7 @@ export default function init(inputIds, filters, operations) {
3535
.use(markdownitSub)
3636
.use(mdItPluginTex.tex, { render: (content) => content, delimiters: 'brackets' })
3737
.use(asciimathBlock)
38-
.use(markdownitrules, { filters: inputFilters, collector: blockCollector });
38+
.use(markdownitrules, { transforms: inputTransforms, collector: blockCollector });
3939

4040
function convertMarkdown(markdown) {
4141
const html = previewMarkdownConverter.render(markdown);

samplequestions/stacklibrary/Features/input-type-sample-questions/Free-text_final_answer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<p>Work line by line below, justifying your answer fully. Your last line should be your answer \(f(x)=...\).</p>
1111
1212
<p>[[input:ans1]] [[validation:ans1]]</p>
13-
[[ascii input="ans1" filters="latexwrap"]]
13+
[[ascii input="ans1" transforms="latexwrap"]]
1414
[[extractor targetinput="ans2" type="finalfunction"/]]
1515
[[/ascii]]
1616
<p>[[hint title="Input help"]][[commonstring key="free_text_fact"/]][[/hint]]</p>

stack/cas/castext2/blocks/ascii.block.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function compile($format, $options): ?MP_Node {
4242
// Define iframe params.
4343
$xpars = [];
4444
$inputs = [];
45-
$xpars['filters'] = '';
45+
$xpars['transforms'] = '';
4646

4747
foreach ($this->params as $key => $value) {
4848
if ($key === 'input') {
@@ -115,7 +115,7 @@ public function compile($format, $options): ?MP_Node {
115115
return 'stack_js.request_access_to_input("' . $item . '"' . $extra . ')';
116116
}, $inputs, array_keys($inputs)));
117117
$linkcode = 'Promise.all([' . $answercalls . '])';
118-
$linkcode .= ".then((inputIds) => {init(inputIds,'" . $xpars['filters'] . "'," . json_encode($operations) . ");});";
118+
$linkcode .= ".then((inputIds) => {init(inputIds,'" . $xpars['transforms'] . "'," . json_encode($operations) . ");});";
119119

120120
$r->items[] = new MP_String($linkcode);
121121
$r->items[] = new MP_String("\n</script>");
@@ -235,13 +235,13 @@ public function validate(
235235
$key !== 'aspect-ratio' &&
236236
$key !== 'input' &&
237237
$key !== 'hidden' &&
238-
$key !== 'filters'
238+
$key !== 'transforms'
239239
) {
240240
$err[] = stack_string('stackBlock_ascii_unknown_param', $key);
241241
$valid = false;
242242
if ($valids === null) {
243243
$valids = [
244-
'width', 'height', 'aspect-ratio', 'input', 'hidden', 'filters'
244+
'width', 'height', 'aspect-ratio', 'input', 'hidden', 'transforms'
245245
];
246246
$err[] = stack_string('stackBlock_ascii_param', [
247247
'param' => implode(', ', $valids),

0 commit comments

Comments
 (0)