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 {
methods: {
preProcess(isWrap, value) {
const formattedContent = formatter(value);
const templatedContent = templater(isWrap, formattedContent);
const templatedContent = isWrap
? templater.wrap(formattedContent)
: templater.unwrap(formattedContent);
return templatedContent;
},
onInputChange(newVal) {
......
// eslint-disable-next-line @gitlab/require-i18n-strings
const marker = ' sse';
const marker = 'sse';
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 code = '.| |\\t|\\n(?!\\n)';
const templatedRegex = new RegExp(`(^${prefix}(${code})+${postfix}$)`, 'gm');
......@@ -30,6 +29,4 @@ const wrap = source => {
return text;
};
const template = (isWrap, source) => (isWrap ? wrap(source) : unwrap(source));
export default template;
export default { wrap, unwrap };
/* eslint-disable no-useless-escape */
import templater from '~/static_site_editor/services/templater';
describe('templater', () => {
......@@ -6,6 +7,12 @@ describe('templater', () => {
<% some erb code %>
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
......@@ -14,18 +21,26 @@ 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`
isWrap | initial | target
${true} | ${source} | ${sourceTemplated}
${true} | ${sourceTemplated} | ${sourceTemplated}
${false} | ${sourceTemplated} | ${source}
${false} | ${source} | ${source}
fn | initial | target
${'wrap'} | ${source} | ${sourceTemplated}
${'wrap'} | ${sourceTemplated} | ${sourceTemplated}
${'unwrap'} | ${sourceTemplated} | ${source}
${'unwrap'} | ${source} | ${source}
`(
'wraps $initial in a templated sse codeblock when $isWrap and unwraps otherwise',
({ isWrap, initial, target }) => {
expect(templater(isWrap, initial)).toMatch(target);
'wraps $initial in a templated sse codeblock if $fn is wrap, unwraps otherwise',
({ fn, initial, 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