diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/blob_edit/blob_bundle.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/blob_edit/edit_blob.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/editor/extensions/source_editor_markdown_ext.js | 18 | ||||
-rw-r--r-- | app/assets/javascripts/ide/components/repo_editor.vue | 6 | ||||
-rw-r--r-- | app/assets/javascripts/ide/index.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/state.js | 1 | ||||
-rw-r--r-- | app/helpers/blob_helper.rb | 3 | ||||
-rw-r--r-- | app/helpers/ide_helper.rb | 3 |
8 files changed, 22 insertions, 19 deletions
diff --git a/app/assets/javascripts/blob_edit/blob_bundle.js b/app/assets/javascripts/blob_edit/blob_bundle.js index 76d9b18b777..2d9ffda06d0 100644 --- a/app/assets/javascripts/blob_edit/blob_bundle.js +++ b/app/assets/javascripts/blob_edit/blob_bundle.js @@ -69,6 +69,7 @@ export default () => { const currentAction = $('.js-file-title').data('currentAction'); const projectId = editBlobForm.data('project-id'); const isMarkdown = editBlobForm.data('is-markdown'); + const previewMarkdownPath = editBlobForm.data('previewMarkdownPath'); const commitButton = $('.js-commit-button'); const cancelLink = $('.btn.btn-cancel'); @@ -80,6 +81,7 @@ export default () => { currentAction, projectId, isMarkdown, + previewMarkdownPath, }); initPopovers(); initCodeQualityWalkthroughStep(); diff --git a/app/assets/javascripts/blob_edit/edit_blob.js b/app/assets/javascripts/blob_edit/edit_blob.js index e068910c626..118cef59d5a 100644 --- a/app/assets/javascripts/blob_edit/edit_blob.js +++ b/app/assets/javascripts/blob_edit/edit_blob.js @@ -11,7 +11,7 @@ import { BLOB_EDITOR_ERROR, BLOB_PREVIEW_ERROR } from './constants'; export default class EditBlob { // The options object has: - // assetsPath, filePath, currentAction, projectId, isMarkdown + // assetsPath, filePath, currentAction, projectId, isMarkdown, previewMarkdownPath constructor(options) { this.options = options; this.configureMonacoEditor(); @@ -30,7 +30,10 @@ export default class EditBlob { import('~/editor/extensions/source_editor_markdown_ext') .then(({ EditorMarkdownExtension: MarkdownExtension } = {}) => { this.editor.use( - new MarkdownExtension({ instance: this.editor, projectPath: this.options.projectPath }), + new MarkdownExtension({ + instance: this.editor, + previewMarkdownPath: this.options.previewMarkdownPath, + }), ); this.hasMarkdownExtension = true; addEditorMarkdownListeners(this.editor); diff --git a/app/assets/javascripts/editor/extensions/source_editor_markdown_ext.js b/app/assets/javascripts/editor/extensions/source_editor_markdown_ext.js index 76e009164f7..57de21c933e 100644 --- a/app/assets/javascripts/editor/extensions/source_editor_markdown_ext.js +++ b/app/assets/javascripts/editor/extensions/source_editor_markdown_ext.js @@ -14,17 +14,9 @@ import { } from '../constants'; import { SourceEditorExtension } from './source_editor_extension_base'; -const getPreview = (text, projectPath = '') => { - let url; - - if (projectPath) { - url = `/${projectPath}/preview_markdown`; - } else { - const { group, project } = document.body.dataset; - url = `/${group}/${project}/preview_markdown`; - } +const getPreview = (text, previewMarkdownPath) => { return axios - .post(url, { + .post(previewMarkdownPath, { text, }) .then(({ data }) => { @@ -43,10 +35,10 @@ const setupDomElement = ({ injectToEl = null } = {}) => { }; export class EditorMarkdownExtension extends SourceEditorExtension { - constructor({ instance, projectPath, ...args } = {}) { + constructor({ instance, previewMarkdownPath, ...args } = {}) { super({ instance, ...args }); Object.assign(instance, { - projectPath, + previewMarkdownPath, preview: { el: undefined, action: undefined, @@ -112,7 +104,7 @@ export class EditorMarkdownExtension extends SourceEditorExtension { fetchPreview() { const { el: previewEl } = this.preview; - getPreview(this.getValue(), this.projectPath) + getPreview(this.getValue(), this.previewMarkdownPath) .then((data) => { previewEl.innerHTML = sanitize(data); syntaxHighlight(previewEl.querySelectorAll('.js-syntax-highlight')); diff --git a/app/assets/javascripts/ide/components/repo_editor.vue b/app/assets/javascripts/ide/components/repo_editor.vue index 2f990280367..2bf99550bf2 100644 --- a/app/assets/javascripts/ide/components/repo_editor.vue +++ b/app/assets/javascripts/ide/components/repo_editor.vue @@ -79,6 +79,7 @@ export default { 'editorTheme', 'entries', 'currentProjectId', + 'previewMarkdownPath', ]), ...mapGetters([ 'getAlert', @@ -314,14 +315,15 @@ export default { if ( this.fileType === MARKDOWN_FILE_TYPE && - this.editor?.getEditorType() === EDITOR_TYPE_CODE + this.editor?.getEditorType() === EDITOR_TYPE_CODE && + this.previewMarkdownPath ) { import('~/editor/extensions/source_editor_markdown_ext') .then(({ EditorMarkdownExtension: MarkdownExtension } = {}) => { this.editor.use( new MarkdownExtension({ instance: this.editor, - projectPath: this.currentProjectId, + previewMarkdownPath: this.previewMarkdownPath, }), ); }) diff --git a/app/assets/javascripts/ide/index.js b/app/assets/javascripts/ide/index.js index e8c726d6184..bdffed70882 100644 --- a/app/assets/javascripts/ide/index.js +++ b/app/assets/javascripts/ide/index.js @@ -63,6 +63,7 @@ export function initIde(el, options = {}) { editorTheme: window.gon?.user_color_scheme || DEFAULT_THEME, codesandboxBundlerUrl: el.dataset.codesandboxBundlerUrl, environmentsGuidanceAlertDismissed: !parseBoolean(el.dataset.enableEnvironmentsGuidance), + previewMarkdownPath: el.dataset.previewMarkdownPath, }); }, beforeDestroy() { diff --git a/app/assets/javascripts/ide/stores/state.js b/app/assets/javascripts/ide/stores/state.js index 83551e87f09..526987c750a 100644 --- a/app/assets/javascripts/ide/stores/state.js +++ b/app/assets/javascripts/ide/stores/state.js @@ -32,4 +32,5 @@ export default () => ({ codesandboxBundlerUrl: null, environmentsGuidanceAlertDismissed: false, environmentsGuidanceAlertDetected: false, + previewMarkdownPath: '', }); diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index eccd0e7a34c..c1a33794b50 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -220,7 +220,8 @@ module BlobHelper 'assets-prefix' => Gitlab::Application.config.assets.prefix, 'blob-filename' => @blob && @blob.path, 'project-id' => project.id, - 'is-markdown' => @blob && @blob.path && Gitlab::MarkupHelper.gitlab_markdown?(@blob.path) + 'is-markdown' => @blob && @blob.path && Gitlab::MarkupHelper.gitlab_markdown?(@blob.path), + 'preview-markdown-path' => preview_markdown_path(project) } end diff --git a/app/helpers/ide_helper.rb b/app/helpers/ide_helper.rb index 41c7abbbabd..09ff57e2baf 100644 --- a/app/helpers/ide_helper.rb +++ b/app/helpers/ide_helper.rb @@ -19,7 +19,8 @@ module IdeHelper 'merge-request' => @merge_request, 'fork-info' => @fork_info&.to_json, 'project' => convert_to_project_entity_json(@project), - 'enable-environments-guidance' => enable_environments_guidance?.to_s + 'enable-environments-guidance' => enable_environments_guidance?.to_s, + 'preview-markdown-path' => @project && preview_markdown_path(@project) } end |