diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-07 03:09:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-07 03:09:52 +0300 |
commit | 3c9c771dcf7886832c57cfedb14dd2c0bc70e706 (patch) | |
tree | a92af9d26bb4d76d99e53c16596097bfcfa03d78 /app/assets/javascripts | |
parent | 0790cf032c70b3df250e1953a3a11b71d835c5a1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/ide/components/ide_project_header.vue | 6 | ||||
-rw-r--r-- | app/assets/javascripts/static_site_editor/services/templater.js | 56 |
2 files changed, 48 insertions, 14 deletions
diff --git a/app/assets/javascripts/ide/components/ide_project_header.vue b/app/assets/javascripts/ide/components/ide_project_header.vue index 36bc7c70196..36891505230 100644 --- a/app/assets/javascripts/ide/components/ide_project_header.vue +++ b/app/assets/javascripts/ide/components/ide_project_header.vue @@ -20,7 +20,11 @@ export default { <project-avatar-default :project="project" :size="48" /> <span class="ide-sidebar-project-title"> <span class="sidebar-context-title"> {{ project.name }} </span> - <span class="sidebar-context-title text-secondary"> + <span + class="sidebar-context-title text-secondary" + data-qa-selector="project_path_content" + :data-qa-project-path="project.path_with_namespace" + > {{ project.path_with_namespace }} </span> </span> diff --git a/app/assets/javascripts/static_site_editor/services/templater.js b/app/assets/javascripts/static_site_editor/services/templater.js index 29a2bcd2e34..081db60b601 100644 --- a/app/assets/javascripts/static_site_editor/services/templater.js +++ b/app/assets/javascripts/static_site_editor/services/templater.js @@ -1,32 +1,62 @@ -const marker = 'sse'; const ticks = '```'; +const marker = 'sse'; 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'); -const embeddedRubyRegex = new RegExp(`(^<%(${code})+%>$)`, 'gm'); +const flagPrefix = `${marker}-${Date.now()}`; +const template = `.| |\\t|\\n(?!(\\n|${flagPrefix}))`; +const templatedRegex = new RegExp(`(^${prefix}(${template})+?${postfix}$)`, 'gm'); + +const nonErbMarkupRegex = new RegExp(`^((<(?!%).+>){1}(${template})+(</.+>){1})$`, 'gm'); +const embeddedRubyBlockRegex = new RegExp(`(^<%(${template})+%>$)`, 'gm'); +const embeddedRubyInlineRegex = new RegExp(`(^.*[<|<]%(${template})+$)`, 'gm'); + +// Order is intentional (general to specific) where HTML markup is flagged first, then ERB blocks, then inline ERB +// Order in combo with the `flag()` algorithm is used to mitigate potential duplicate pattern matches (ERB nested in HTML for example) +const orderedPatterns = [nonErbMarkupRegex, embeddedRubyBlockRegex, embeddedRubyInlineRegex]; const unwrap = source => { let text = source; const matches = text.match(templatedRegex); + if (matches) { matches.forEach(match => { - const initial = match.replace(prefix, '').replace(postfix, ''); + const initial = match.replace(`${prefix}`, '').replace(`${postfix}`, ''); text = text.replace(match, initial); }); } + return text; }; +const flag = (source, patterns) => { + let text = source; + let id = 0; + const hash = {}; + + patterns.forEach(pattern => { + const matches = text.match(pattern); + if (matches) { + matches.forEach(match => { + const key = `${flagPrefix}${id}`; + text = text.replace(match, key); + hash[key] = match; + id += 1; + }); + } + }); + + return { text, hash }; +}; + const wrap = source => { - let text = unwrap(source); - const matches = text.match(embeddedRubyRegex); - if (matches) { - matches.forEach(match => { - text = text.replace(match, `${prefix}${match}${postfix}`); - }); - } - return text; + const { text, hash } = flag(unwrap(source), orderedPatterns); + + let wrappedSource = text; + Object.entries(hash).forEach(([key, value]) => { + wrappedSource = wrappedSource.replace(key, `${prefix}${value}${postfix}`); + }); + + return wrappedSource; }; export default { wrap, unwrap }; |