Skip to content

Commit

Permalink
[zmarkdown] Make enforce_shift the default and drop the option
Browse files Browse the repository at this point in the history
  • Loading branch information
StaloneLab committed Apr 27, 2024
1 parent 07983fa commit 32ffebd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Regression tests HTML endpoint #188 It does not crash on unsupported languages fenced code blocks 1`] = `
"<h3 id=\\"foo\\">foo<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#foo\\"><span class=\\"icon icon-link\\"></span></a></h3>
"<h1 id=\\"foo\\">foo<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#foo\\"><span class=\\"icon icon-link\\"></span></a></h1>
<div class=\\"hljs-code-div hljs-code-foobar\\"><pre><code class=\\"hljs language-foobar\\">console.error(\\"foo\\", true)
</code></pre></div>
<div class=\\"hljs-code-div hljs-code-js\\"><pre><code class=\\"hljs language-js\\"><span class=\\"hljs-built_in\\">console</span>.error(<span class=\\"hljs-string\\">\\"foo\\"</span>, <span class=\\"hljs-literal\\">true</span>)
Expand Down
14 changes: 7 additions & 7 deletions packages/zmarkdown/__tests__/__snapshots__/server.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HTML endpoint accepts POSTed markdown 1`] = `"<h3 id=\\"foo\\">foo<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#foo\\"><span class=\\"icon icon-link\\"></span></a></h3>"`;
exports[`HTML endpoint can enforce shifting level 1`] = `
"<h2 id=\\"i-have-seen-a-dolphin\\">I have seen a dolphin<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#i-have-seen-a-dolphin\\"><span class=\\"icon icon-link\\"></span></a></h2>
<p>On a camera. What is happening with animals these days?\\"</p>"
`;
exports[`HTML endpoint accepts POSTed markdown 1`] = `"<h1 id=\\"foo\\">foo<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#foo\\"><span class=\\"icon icon-link\\"></span></a></h1>"`;
exports[`HTML endpoint correctly renders manifest 1`] = `
Object {
Expand All @@ -25,9 +20,14 @@ Object {
}
`;
exports[`HTML endpoint enforce level shifting by default 1`] = `
"<h2 id=\\"i-have-seen-a-dolphin\\">I have seen a dolphin<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#i-have-seen-a-dolphin\\"><span class=\\"icon icon-link\\"></span></a></h2>
<p>On a camera. What is happening with animals these days?\\"</p>"
`;
exports[`HTML endpoint produces statistics when configured 1`] = `
"<p>7 chars</p>
<h3 id=\\"13-chars-here\\">13 chars here<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#13-chars-here\\"><span class=\\"icon icon-link\\"></span></a></h3>
<h1 id=\\"13-chars-here\\">13 chars here<a aria-hidden=\\"true\\" tabindex=\\"-1\\" href=\\"#13-chars-here\\"><span class=\\"icon icon-link\\"></span></a></h1>
<p><a href=\\"https.//github.com/zestedesavoir/zmarkdown\\">13 chars here</a></p>
<figure><img src=\\"https.//github.com/zestedesavoir/zmarkdown\\" alt=\\"13 chars here\\" loading=\\"lazy\\"><figcaption>13 chars here</figcaption></figure>
<figure><img src=\\"https.//github.com/zestedesavoir/zmarkdown\\" alt=\\"no chars here\\" loading=\\"lazy\\"><figcaption>13 chars here</figcaption></figure>"
Expand Down
4 changes: 2 additions & 2 deletions packages/zmarkdown/__tests__/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ describe('HTML endpoint', () => {
expect(metadata.hasQuizz).toBe(true)
})

it('can enforce shifting level', async () => {
it('enforce level shifting by default', async () => {
const text = dedent(`
# I have seen a dolphin
On a camera. What is happening with animals these days?"
`)

const response = await a.post(html, {md: text, opts: {heading_shift: 1, enforce_shift: true}})
const response = await a.post(html, {md: text, opts: {heading_shift: 1}})
expect(response.status).toBe(200)

const [content] = response.data
Expand Down
2 changes: 1 addition & 1 deletion packages/zmarkdown/server/factories/controller-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (givenProc, template) => (req, res, next) => {
localOptions.ic_shift = localOptions.depth
}

const mergedOptions = Object.assign({ enforce_shift: true }, options, localOptions)
const mergedOptions = Object.assign({}, options, localOptions)
const processor = processorFactory(givenProc, mergedOptions)

return processor(text)
Expand Down
3 changes: 0 additions & 3 deletions packages/zmarkdown/server/factories/processor-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ module.exports = (processor, opts = {}) => {
}

if (processor === 'html') {
if (!opts.enforce_shift) opts.heading_shift = 2
opts.disable_images_download = true
}

if (processor === 'latex') {
if (!opts.enforce_shift) opts.heading_shift = 0
opts.disable_ping = true
opts.disable_jsfiddle = true
} else {
delete opts.extract_type
}

if (processor === 'epub') {
if (!opts.enforce_shift) opts.heading_shift = 2
opts.disable_ping = true
opts.disable_jsfiddle = true
opts.inline = false
Expand Down

0 comments on commit 32ffebd

Please sign in to comment.