Replace codemirror theme indent hardcoding

This commit is contained in:
Rob Garrison 2018-07-21 09:49:20 -05:00
parent a3dbc627d1
commit f4d1f36ce1
2 changed files with 7 additions and 5 deletions

View File

@ -537,7 +537,7 @@ onDOMscriptReady('/codemirror.js').then(() => {
'xq-dark',
'xq-light',
'yeti',
'zenburn'
'zenburn',
/* populate-theme-end */
];
localStorage.codeMirrorThemes = themes.join(' ');

View File

@ -15,11 +15,13 @@ async function getThemes() {
}
function replaceThemes(content, themes) {
const list = JSON.stringify(themes, null, 8).replace(/"/g, '\'');
const lineFeed = content.includes('\r\n') ? '\r\n' : '\n';
return content.replace(
/\/\*\s*populate-theme-start\s*\*\/[\s\S]+\/\*\s*populate-theme-end\s*\*\//,
// strip off square brackets & first 8 spaces
`/* populate-theme-start */\n${list.substring(2, list.length - 2)}\n /* populate-theme-end */`
/(\x20+)(\/\*\s*populate-theme-start\s*\*\/)[\s\S]+?(\/\*\s*populate-theme-end\s*\*\/)/,
(_, indent, intro, outro) =>
indent + intro + lineFeed +
themes.map(_ => `${indent}'${_}',`).join(lineFeed) + lineFeed +
indent + outro
);
}