diff --git a/src/components/editor/editor.tsx b/src/components/editor/editor.tsx index 53d4b0faa..c3f6eb6cc 100644 --- a/src/components/editor/editor.tsx +++ b/src/components/editor/editor.tsx @@ -6,7 +6,7 @@ import { setEditorModeConfig } from '../../redux/editor/methods' import { Splitter } from '../common/splitter/splitter' import { InfoBanner } from '../landing/layout/info-banner' import { EditorWindow } from './editor-window/editor-window' -import { MarkdownPreview } from './markdown-preview/markdown-preview' +import { MarkdownRenderer } from './markdown-renderer/markdown-renderer' import { EditorMode } from './task-bar/editor-view-mode' import { TaskBar } from './task-bar/task-bar' @@ -50,7 +50,7 @@ https://vimeo.com/23237102 showLeft={editorMode === EditorMode.EDITOR || editorMode === EditorMode.BOTH} left={ setMarkdownContent(content)} content={markdownContent}/>} showRight={editorMode === EditorMode.PREVIEW || (editorMode === EditorMode.BOTH)} - right={} + right={} containerClassName={'overflow-hidden'}/> diff --git a/src/components/editor/markdown-preview/replace-components/video-util.ts b/src/components/editor/markdown-preview/replace-components/video-util.ts deleted file mode 100644 index 6ab7dc44d..000000000 --- a/src/components/editor/markdown-preview/replace-components/video-util.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { DomElement } from 'domhandler' - -export const getIdFromCodiMdTag = (node: DomElement, tagName: string): (string | undefined) => { - if (node.name !== `codimd-${tagName}` || !node.attribs || !node.attribs.id) { - return - } - return node.attribs.id -} - -export interface VideoFrameProps { - id: string -} diff --git a/src/components/editor/markdown-preview/container-plugins/alert.ts b/src/components/editor/markdown-renderer/container-plugins/alert.ts similarity index 100% rename from src/components/editor/markdown-preview/container-plugins/alert.ts rename to src/components/editor/markdown-renderer/container-plugins/alert.ts diff --git a/src/components/editor/markdown-preview/markdown-it-plugins/parser-debugger.ts b/src/components/editor/markdown-renderer/markdown-it-plugins/parser-debugger.ts similarity index 100% rename from src/components/editor/markdown-preview/markdown-it-plugins/parser-debugger.ts rename to src/components/editor/markdown-renderer/markdown-it-plugins/parser-debugger.ts diff --git a/src/components/editor/markdown-preview/markdown-preview.scss b/src/components/editor/markdown-renderer/markdown-renderer.scss similarity index 100% rename from src/components/editor/markdown-preview/markdown-preview.scss rename to src/components/editor/markdown-renderer/markdown-renderer.scss diff --git a/src/components/editor/markdown-preview/markdown-preview.tsx b/src/components/editor/markdown-renderer/markdown-renderer.tsx similarity index 97% rename from src/components/editor/markdown-preview/markdown-preview.tsx rename to src/components/editor/markdown-renderer/markdown-renderer.tsx index 1cc1874b7..2a3e8d552 100644 --- a/src/components/editor/markdown-preview/markdown-preview.tsx +++ b/src/components/editor/markdown-renderer/markdown-renderer.tsx @@ -15,7 +15,7 @@ import React, { ReactElement, useMemo } from 'react' import ReactHtmlParser, { convertNodeToElement, Transform } from 'react-html-parser' import { createRenderContainer, validAlertLevels } from './container-plugins/alert' import { MarkdownItParserDebugger } from './markdown-it-plugins/parser-debugger' -import './markdown-preview.scss' +import './markdown-renderer.scss' import { replaceGistLink } from './regex-plugins/replace-gist-link' import { replaceLegacyGistShortCode } from './regex-plugins/replace-legacy-gist-short-code' import { replaceLegacySlideshareShortCode } from './regex-plugins/replace-legacy-slideshare-short-code' @@ -47,7 +47,7 @@ const tryToReplaceNode = (node: DomElement, componentReplacer2Identifier2Counter .find((replacement) => !!replacement) } -const MarkdownPreview: React.FC = ({ content }) => { +const MarkdownRenderer: React.FC = ({ content }) => { const markdownIt = useMemo(() => { const md = new MarkdownIt('default', { html: true, @@ -98,4 +98,4 @@ const MarkdownPreview: React.FC = ({ content }) => { ) } -export { MarkdownPreview } +export { MarkdownRenderer } diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-gist-link.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-gist-link.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-gist-link.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-gist-link.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-legacy-gist-short-code.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-legacy-gist-short-code.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-legacy-gist-short-code.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-legacy-gist-short-code.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-legacy-slideshare-short-code.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-legacy-slideshare-short-code.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-legacy-slideshare-short-code.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-legacy-slideshare-short-code.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-legacy-speakerdeck-short-code.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-legacy-speakerdeck-short-code.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-legacy-speakerdeck-short-code.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-legacy-speakerdeck-short-code.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-legacy-vimeo-short-code.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-legacy-vimeo-short-code.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-legacy-vimeo-short-code.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-legacy-vimeo-short-code.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-legacy-youtube-short-code.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-legacy-youtube-short-code.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-legacy-youtube-short-code.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-legacy-youtube-short-code.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-pdf-short-code.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-pdf-short-code.ts similarity index 86% rename from src/components/editor/markdown-preview/regex-plugins/replace-pdf-short-code.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-pdf-short-code.ts index 6163ab582..68cc41688 100644 --- a/src/components/editor/markdown-preview/regex-plugins/replace-pdf-short-code.ts +++ b/src/components/editor/markdown-renderer/regex-plugins/replace-pdf-short-code.ts @@ -6,6 +6,6 @@ export const replacePdfShortCode: RegexOptions = { replace: (match) => { // ESLint wants to collapse this tag, but then the tag won't be valid html anymore. // noinspection CheckTagEmptyBody - return `` + return `` } } diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-vimeo-link.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-vimeo-link.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-vimeo-link.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-vimeo-link.ts diff --git a/src/components/editor/markdown-preview/regex-plugins/replace-youtube-link.ts b/src/components/editor/markdown-renderer/regex-plugins/replace-youtube-link.ts similarity index 100% rename from src/components/editor/markdown-preview/regex-plugins/replace-youtube-link.ts rename to src/components/editor/markdown-renderer/regex-plugins/replace-youtube-link.ts diff --git a/src/components/editor/markdown-renderer/replace-components/codi-md-tag-utils.ts b/src/components/editor/markdown-renderer/replace-components/codi-md-tag-utils.ts new file mode 100644 index 000000000..0dcd1cafa --- /dev/null +++ b/src/components/editor/markdown-renderer/replace-components/codi-md-tag-utils.ts @@ -0,0 +1,8 @@ +import { DomElement } from 'domhandler' + +export const getAttributesFromCodiMdTag = (node: DomElement, tagName: string): ({ [s: string]: string; }|undefined) => { + if (node.name !== `codimd-${tagName}` || !node.attribs) { + return + } + return node.attribs +} diff --git a/src/components/editor/markdown-preview/replace-components/gist/gist-frame.scss b/src/components/editor/markdown-renderer/replace-components/gist/gist-frame.scss similarity index 100% rename from src/components/editor/markdown-preview/replace-components/gist/gist-frame.scss rename to src/components/editor/markdown-renderer/replace-components/gist/gist-frame.scss diff --git a/src/components/editor/markdown-preview/replace-components/gist/gist-frame.tsx b/src/components/editor/markdown-renderer/replace-components/gist/gist-frame.tsx similarity index 90% rename from src/components/editor/markdown-preview/replace-components/gist/gist-frame.tsx rename to src/components/editor/markdown-renderer/replace-components/gist/gist-frame.tsx index b6184ca9b..4327610f3 100644 --- a/src/components/editor/markdown-preview/replace-components/gist/gist-frame.tsx +++ b/src/components/editor/markdown-renderer/replace-components/gist/gist-frame.tsx @@ -1,7 +1,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react' -import { ComponentReplacer } from '../../markdown-preview' +import { ComponentReplacer } from '../../markdown-renderer' +import { getAttributesFromCodiMdTag } from '../codi-md-tag-utils' import { OneClickEmbedding } from '../one-click-frame/one-click-embedding' -import { getIdFromCodiMdTag } from '../video-util' import './gist-frame.scss' import preview from './gist-preview.png' @@ -15,8 +15,9 @@ interface resizeEvent { } const getElementReplacement:ComponentReplacer = (node, counterMap) => { - const gistId = getIdFromCodiMdTag(node, 'gist') - if (gistId) { + const attributes = getAttributesFromCodiMdTag(node, 'gist') + if (attributes && attributes.id) { + const gistId = attributes.id const count = (counterMap.get(gistId) || 0) + 1 counterMap.set(gistId, count) return ( diff --git a/src/components/editor/markdown-preview/replace-components/gist/gist-preview.png b/src/components/editor/markdown-renderer/replace-components/gist/gist-preview.png similarity index 100% rename from src/components/editor/markdown-preview/replace-components/gist/gist-preview.png rename to src/components/editor/markdown-renderer/replace-components/gist/gist-preview.png diff --git a/src/components/editor/markdown-preview/replace-components/one-click-frame/one-click-embedding.scss b/src/components/editor/markdown-renderer/replace-components/one-click-frame/one-click-embedding.scss similarity index 100% rename from src/components/editor/markdown-preview/replace-components/one-click-frame/one-click-embedding.scss rename to src/components/editor/markdown-renderer/replace-components/one-click-frame/one-click-embedding.scss diff --git a/src/components/editor/markdown-preview/replace-components/one-click-frame/one-click-embedding.tsx b/src/components/editor/markdown-renderer/replace-components/one-click-frame/one-click-embedding.tsx similarity index 100% rename from src/components/editor/markdown-preview/replace-components/one-click-frame/one-click-embedding.tsx rename to src/components/editor/markdown-renderer/replace-components/one-click-frame/one-click-embedding.tsx diff --git a/src/components/editor/markdown-preview/replace-components/pdf/pdf-frame.scss b/src/components/editor/markdown-renderer/replace-components/pdf/pdf-frame.scss similarity index 100% rename from src/components/editor/markdown-preview/replace-components/pdf/pdf-frame.scss rename to src/components/editor/markdown-renderer/replace-components/pdf/pdf-frame.scss diff --git a/src/components/editor/markdown-preview/replace-components/pdf/pdf-frame.tsx b/src/components/editor/markdown-renderer/replace-components/pdf/pdf-frame.tsx similarity index 61% rename from src/components/editor/markdown-preview/replace-components/pdf/pdf-frame.tsx rename to src/components/editor/markdown-renderer/replace-components/pdf/pdf-frame.tsx index bd8bcb31b..89674b02a 100644 --- a/src/components/editor/markdown-preview/replace-components/pdf/pdf-frame.tsx +++ b/src/components/editor/markdown-renderer/replace-components/pdf/pdf-frame.tsx @@ -1,26 +1,31 @@ import { DomElement } from 'domhandler' import React, { ReactElement } from 'react' import { ExternalLink } from '../../../../common/links/external-link' +import { getAttributesFromCodiMdTag } from '../codi-md-tag-utils' import { OneClickEmbedding } from '../one-click-frame/one-click-embedding' -import { getIdFromCodiMdTag, VideoFrameProps } from '../video-util' import './pdf-frame.scss' const getElementReplacement = (node: DomElement, counterMap: Map): (ReactElement | undefined) => { - const pdfUrl = getIdFromCodiMdTag(node, 'pdf') - if (pdfUrl) { + const attributes = getAttributesFromCodiMdTag(node, 'pdf') + if (attributes && attributes.url) { + const pdfUrl = attributes.url const count = (counterMap.get(pdfUrl) || 0) + 1 counterMap.set(pdfUrl, count) - return + return } } -export const PdfFrame: React.FC = ({ id }) => { +export interface PdfFrameProps { + url: string +} + +export const PdfFrame: React.FC = ({ url }) => { return ( - - + + ) diff --git a/src/components/editor/markdown-preview/replace-components/vimeo/vimeo-frame.tsx b/src/components/editor/markdown-renderer/replace-components/vimeo/vimeo-frame.tsx similarity index 82% rename from src/components/editor/markdown-preview/replace-components/vimeo/vimeo-frame.tsx rename to src/components/editor/markdown-renderer/replace-components/vimeo/vimeo-frame.tsx index 2d78897cf..9738401d2 100644 --- a/src/components/editor/markdown-preview/replace-components/vimeo/vimeo-frame.tsx +++ b/src/components/editor/markdown-renderer/replace-components/vimeo/vimeo-frame.tsx @@ -1,11 +1,12 @@ import React, { useCallback } from 'react' -import { ComponentReplacer } from '../../markdown-preview' +import { ComponentReplacer } from '../../markdown-renderer' +import { getAttributesFromCodiMdTag } from '../codi-md-tag-utils' import { OneClickEmbedding } from '../one-click-frame/one-click-embedding' -import { getIdFromCodiMdTag, VideoFrameProps } from '../video-util' const getElementReplacement:ComponentReplacer = (node, counterMap) => { - const videoId = getIdFromCodiMdTag(node, 'vimeo') - if (videoId) { + const attributes = getAttributesFromCodiMdTag(node, 'vimeo') + if (attributes && attributes.id) { + const videoId = attributes.id const count = (counterMap.get(videoId) || 0) + 1 counterMap.set(videoId, count) return @@ -18,7 +19,11 @@ interface VimeoApiResponse { thumbnail_large?: string } -export const VimeoFrame: React.FC = ({ id }) => { +export interface VimeoFrameProps { + id: string +} + +export const VimeoFrame: React.FC = ({ id }) => { const getPreviewImageLink = useCallback(async () => { const response = await fetch(`https://vimeo.com/api/v2/video/${id}.json`, { credentials: 'omit', diff --git a/src/components/editor/markdown-preview/replace-components/youtube/youtube-frame.tsx b/src/components/editor/markdown-renderer/replace-components/youtube/youtube-frame.tsx similarity index 70% rename from src/components/editor/markdown-preview/replace-components/youtube/youtube-frame.tsx rename to src/components/editor/markdown-renderer/replace-components/youtube/youtube-frame.tsx index 03d9c9a9f..f4a933a8c 100644 --- a/src/components/editor/markdown-preview/replace-components/youtube/youtube-frame.tsx +++ b/src/components/editor/markdown-renderer/replace-components/youtube/youtube-frame.tsx @@ -1,18 +1,23 @@ import React from 'react' -import { ComponentReplacer } from '../../markdown-preview' +import { ComponentReplacer } from '../../markdown-renderer' +import { getAttributesFromCodiMdTag } from '../codi-md-tag-utils' import { OneClickEmbedding } from '../one-click-frame/one-click-embedding' -import { getIdFromCodiMdTag, VideoFrameProps } from '../video-util' const getElementReplacement: ComponentReplacer = (node, counterMap) => { - const videoId = getIdFromCodiMdTag(node, 'youtube') - if (videoId) { + const attributes = getAttributesFromCodiMdTag(node, 'youtube') + if (attributes && attributes.id) { + const videoId = attributes.id const count = (counterMap.get(videoId) || 0) + 1 counterMap.set(videoId, count) return } } -export const YouTubeFrame: React.FC = ({ id }) => { +export interface YouTubeFrameProps { + id: string +} + +export const YouTubeFrame: React.FC = ({ id }) => { return (