π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix:markdown renderer for text field
DarkPhoenix27046a66880511a3
diff --git a/packages/nc-gui/helpers/tiptap-markdown/Markdown.ts b/packages/nc-gui/helpers/tiptap-markdown/Markdown.tsindex 18b67e8a02..bdef207427 100644--- a/packages/nc-gui/helpers/tiptap-markdown/Markdown.ts+++ b/packages/nc-gui/helpers/tiptap-markdown/Markdown.ts@@ -17,6 +17,7 @@ export const Markdown = Extension.create<MarkdownOptions, MarkdownStorage>({breaks: false,transformPastedText: false,transformCopiedText: false,+ renderImagesAsLinks: false,}},addCommands() {diff --git a/packages/nc-gui/helpers/tiptap-markdown/extensions/nodes/image.ts b/packages/nc-gui/helpers/tiptap-markdown/extensions/nodes/image.tsindex 3db9259426..6acb7e7251 100644--- a/packages/nc-gui/helpers/tiptap-markdown/extensions/nodes/image.ts+++ b/packages/nc-gui/helpers/tiptap-markdown/extensions/nodes/image.ts@@ -12,13 +12,10 @@ export const Image = Node.create<any, { markdown: MarkdownNodeSpec }>({serialize: defaultMarkdownSerializer.nodes.image!,parse: {setup(markdownit) {- /**- * Todo: Remove this once we enable proper image support in the rich text editor.- * Also, replace its usage in other places such as:- * 1. packages/nc-gui/helpers/tiptap-markdown/parse/MarkdownParser.ts- * 2. packages/nc-gui/helpers/tiptap-markdown/extensions/nodes/image.ts- */- markdownit.use(mdImageAsText)+ // Conditionally apply mdImageAsText plugin based on renderImagesAsLinks option+ if (this.editor.storage.markdown?.options?.renderImagesAsLinks) {+ markdownit.use(mdImageAsText)+ }},},},diff --git a/packages/nc-gui/helpers/tiptap-markdown/parse/MarkdownParser.ts b/packages/nc-gui/helpers/tiptap-markdown/parse/MarkdownParser.tsindex fbfbb253e8..1a0cdc2ba5 100644--- a/packages/nc-gui/helpers/tiptap-markdown/parse/MarkdownParser.ts+++ b/packages/nc-gui/helpers/tiptap-markdown/parse/MarkdownParser.ts@@ -2,6 +2,7 @@ import MarkdownIt from 'markdown-it'import type { Editor } from '@tiptap/core'import { elementFromString, extractElement, unwrapElement } from '../util/dom'import { getMarkdownSpec } from '../util/extensions'+import type { MarkdownOptions } from '../types'import { mdImageAsText } from '~/helpers/tiptap/functionality'export class MarkdownParser {@@ -9,24 +10,21 @@ export class MarkdownParser {md: MarkdownIt- constructor(editor: Editor, { html, linkify, breaks }: Partial<MarkdownIt.Options>) {+ constructor(editor: Editor, options: Partial<MarkdownOptions & MarkdownIt.Options>) {this.editor = editorthis.md = this.withPatchedRenderer(MarkdownIt({- html,- linkify,- breaks,+ html: options.html,+ linkify: options.linkify,+ breaks: options.breaks,}),)- /**- * Todo: Remove this once we enable proper image support in the rich text editor.- * Also, replace its usage in other places such as:- * 1. packages/nc-gui/helpers/tiptap/functionality/markdown/markdown.ts- * 2. packages/nc-gui/helpers/tiptap-markdown/extensions/nodes/image.ts- */- this.md.use(mdImageAsText)+ // Conditionally apply mdImageAsText plugin based on renderImagesAsLinks option+ if (options.renderImagesAsLinks) {+ this.md.use(mdImageAsText)+ }}parse<T>(content: T, { inline }: { inline?: boolean } = {}): T | string {diff --git a/packages/nc-gui/helpers/tiptap-markdown/types.d.ts b/packages/nc-gui/helpers/tiptap-markdown/types.d.tsindex d54ececa5d..8b76c95793 100644--- a/packages/nc-gui/helpers/tiptap-markdown/types.d.ts+++ b/packages/nc-gui/helpers/tiptap-markdown/types.d.ts@@ -12,6 +12,7 @@ export interface MarkdownOptions {breaks?: booleantransformPastedText?: booleantransformCopiedText?: boolean+ renderImagesAsLinks?: boolean}export interface MarkdownStorage {diff --git a/packages/nc-gui/utils/dashboardUtils.ts b/packages/nc-gui/utils/dashboardUtils.tsindex 10d61b908d..f7cb04b107 100644--- a/packages/nc-gui/utils/dashboardUtils.ts+++ b/packages/nc-gui/utils/dashboardUtils.ts@@ -1,4 +1,4 @@-import { ChartTypes } from 'nocodb-sdk'+import { ChartTypes, TextWidgetTypes } from 'nocodb-sdk'export const chartIconMap = {[ChartTypes.BAR]: 'ncChartBar',@@ -7,3 +7,13 @@ export const chartIconMap = {[ChartTypes.DONUT]: 'ncChartDonut',[ChartTypes.SCATTER]: 'ncChartScatterPlot',}++export const textIconMap = {+ [TextWidgetTypes.Markdown]: 'cellLongText',+ [TextWidgetTypes.Text]: 'cellText',+}++export const textLabelMap = {+ [TextWidgetTypes.Markdown]: 'Markdown',+ [TextWidgetTypes.Text]: 'Text',+}diff --git a/packages/nocodb-sdk/src/lib/dashboard/index.ts b/packages/nocodb-sdk/src/lib/dashboard/index.tsindex 171541771c..0a7cff8bcb 100644--- a/packages/nocodb-sdk/src/lib/dashboard/index.ts+++ b/packages/nocodb-sdk/src/lib/dashboard/index.ts@@ -72,17 +72,22 @@ export interface MetricWidgetConfig {}export enum TextWidgetTypes {- H1 = 'H1',- H2 = 'H2',- H3 = 'H3',- H4 = 'H4',- H5 = 'H5',- H6 = 'H6',+ Markdown = 'markdown',+ Text = 'text',}-export interface TextWidgetConfig {+interface TextWidgetConfigMarkdown {content: string;- type: TextWidgetTypes;+ type: TextWidgetTypes.Markdown;+ formatting: {+ horizontalAlign: 'flex-start' | 'center' | 'flex-end';+ verticalAlign: 'flex-start' | 'center' | 'flex-end';+ };+}++interface TextWidgetConfigText {+ content: string;+ type: TextWidgetTypes.Text;formatting: {horizontalAlign: 'flex-start' | 'center' | 'flex-end';verticalAlign: 'flex-start' | 'center' | 'flex-end';@@ -102,6 +107,8 @@ export interface TextWidgetConfig {};}+export type TextWidgetConfig = TextWidgetConfigMarkdown | TextWidgetConfigText;+export interface IframeWidgetConfig {url: string;height?: number;diff --git a/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts b/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.tsindex d8ed922e7a..ca43f628dd 100644--- a/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts+++ b/packages/nocodb-sdk/src/lib/dashboard/widgetUtils.ts@@ -95,7 +95,7 @@ const getDefaultConfig = (case WidgetTypes.TEXT:return {content: 'Enter text here',- type: TextWidgetTypes.H1,+ type: TextWidgetTypes.Markdown,formatting: {horizontalAlign: 'flex-start',verticalAlign: 'flex-start',