@mieweb/wikigdrive
Version:
Google Drive to MarkDown synchronization
55 lines (54 loc) • 1.99 kB
JavaScript
export function isMarkdownBeginMacro(innerTxt) {
if ('{{markdown}}' === innerTxt)
return true;
if ('{{% markdown %}}' === innerTxt)
return true;
if (innerTxt.startsWith('{{% pre ') && innerTxt.endsWith(' %}}')) {
// return true;
}
return false;
}
export function getMarkdownEndMacro(innerTxt) {
if ('{{markdown}}' === innerTxt)
return '{{/markdown}}';
if ('{{% markdown %}}' === innerTxt)
return '{{% /markdown %}}';
if (innerTxt.startsWith('{{% pre ') && innerTxt.endsWith(' %}}')) {
// return innerTxt.replace('{{% pre ', '{{% /pre ');
}
}
export function isMarkdownEndMacro(innerTxt) {
if ('{{/markdown}}' === innerTxt)
return true;
if ('{{% /markdown %}}' === innerTxt)
return true;
if (innerTxt.startsWith('{{% /pre ') && innerTxt.endsWith(' %}}')) {
// return true;
}
return false;
}
export function isMarkdownMacro(innerTxt) {
const prefix = innerTxt.substring(0, innerTxt.indexOf('}}') + '}}'.length);
const suffix = innerTxt.substring(innerTxt.lastIndexOf('{{'));
return isMarkdownBeginMacro(prefix) && isMarkdownEndMacro(suffix);
}
export function stripMarkdownMacro(innerTxt) {
const prefix = innerTxt.substring(0, innerTxt.indexOf('}}') + '}}'.length);
const suffix = innerTxt.substring(innerTxt.lastIndexOf('{{'));
if (isMarkdownBeginMacro(prefix) && isMarkdownEndMacro(suffix)) {
return innerTxt.substring(prefix.length, innerTxt.length - suffix.length);
}
return innerTxt;
}
export function isBeginMacro(innerTxt) {
return innerTxt.startsWith('{{% ') && !innerTxt.startsWith('{{% /') && innerTxt.endsWith(' %}}');
}
export function getEndMacro(innerTxt) {
const txt = innerTxt.replace('{{% ', '').replace(' %}}', '')
.split(' ')
.shift();
return '{{% /' + txt + ' %}}';
}
export function isEndMacro(innerTxt) {
return innerTxt.startsWith('{{% /') && innerTxt.endsWith(' %}}');
}