Commit 08a78828 authored by derek-knox's avatar derek-knox

Feedback round 1 applied

Add note around intentional marker spacing,
refactor to wrap/unwrap fns fs isWrap flag,
and updated spec to be more robust example
parent cf42fd33
...@@ -62,7 +62,9 @@ export default { ...@@ -62,7 +62,9 @@ export default {
methods: { methods: {
preProcess(isWrap, value) { preProcess(isWrap, value) {
const formattedContent = formatter(value); const formattedContent = formatter(value);
const templatedContent = templater(isWrap, formattedContent); const templatedContent = isWrap
? templater.wrap(formattedContent)
: templater.unwrap(formattedContent);
return templatedContent; return templatedContent;
}, },
onInputChange(newVal) { onInputChange(newVal) {
......
// eslint-disable-next-line @gitlab/require-i18n-strings const marker = 'sse';
const marker = ' sse';
const ticks = '```'; const ticks = '```';
const prefix = `${ticks}${marker}\n`; const prefix = `${ticks} ${marker}\n`; // Space intentional due to https://github.com/nhn/tui.editor/blob/6bcec75c69028570d93d973aa7533090257eaae0/libs/to-mark/src/renderer.gfm.js#L26
const postfix = `\n${ticks}`; const postfix = `\n${ticks}`;
const code = '.| |\\t|\\n(?!\\n)'; const code = '.| |\\t|\\n(?!\\n)';
const templatedRegex = new RegExp(`(^${prefix}(${code})+${postfix}$)`, 'gm'); const templatedRegex = new RegExp(`(^${prefix}(${code})+${postfix}$)`, 'gm');
...@@ -30,6 +29,4 @@ const wrap = source => { ...@@ -30,6 +29,4 @@ const wrap = source => {
return text; return text;
}; };
const template = (isWrap, source) => (isWrap ? wrap(source) : unwrap(source)); export default { wrap, unwrap };
export default template;
/* eslint-disable no-useless-escape */
import templater from '~/static_site_editor/services/templater'; import templater from '~/static_site_editor/services/templater';
describe('templater', () => { describe('templater', () => {
...@@ -6,6 +7,12 @@ describe('templater', () => { ...@@ -6,6 +7,12 @@ describe('templater', () => {
<% some erb code %> <% some erb code %>
Some more text Some more text
<% if apptype.maturity && (apptype.maturity != "planned") %>
<% maturity = "This application type is at the \"#{apptype.maturity}\" level of maturity." %>
<% end %>
With even text with indented code above.
`; `;
const sourceTemplated = `Some text const sourceTemplated = `Some text
...@@ -14,18 +21,26 @@ Some more text ...@@ -14,18 +21,26 @@ Some more text
\`\`\` \`\`\`
Some more text Some more text
\`\`\` sse
<% if apptype.maturity && (apptype.maturity != "planned") %>
<% maturity = "This application type is at the \"#{apptype.maturity}\" level of maturity." %>
<% end %>
\`\`\`
With even text with indented code above.
`; `;
it.each` it.each`
isWrap | initial | target fn | initial | target
${true} | ${source} | ${sourceTemplated} ${'wrap'} | ${source} | ${sourceTemplated}
${true} | ${sourceTemplated} | ${sourceTemplated} ${'wrap'} | ${sourceTemplated} | ${sourceTemplated}
${false} | ${sourceTemplated} | ${source} ${'unwrap'} | ${sourceTemplated} | ${source}
${false} | ${source} | ${source} ${'unwrap'} | ${source} | ${source}
`( `(
'wraps $initial in a templated sse codeblock when $isWrap and unwraps otherwise', 'wraps $initial in a templated sse codeblock if $fn is wrap, unwraps otherwise',
({ isWrap, initial, target }) => { ({ fn, initial, target }) => {
expect(templater(isWrap, initial)).toMatch(target); expect(templater[fn](initial)).toMatch(target);
}, },
); );
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment