From 8a7828da48198a01556f4657a1d6b9669035ab87 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:01:33 +0000 Subject: [PATCH] Update dependency marked to v12 (#82245) * Update dependency marked to v12 * make sure marked return value is synchronous --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ashley Harrison --- package.json | 2 +- packages/grafana-data/package.json | 2 +- packages/grafana-data/src/text/markdown.ts | 21 +++++++++++++++------ packages/grafana-prometheus/package.json | 2 +- yarn.lock | 14 +++++++------- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 6f74bef7510..1d150a5cb47 100644 --- a/package.json +++ b/package.json @@ -329,7 +329,7 @@ "lru-cache": "10.2.0", "lru-memoize": "^1.1.0", "lucene": "^2.1.1", - "marked": "5.1.1", + "marked": "12.0.0", "marked-mangle": "1.1.7", "memoize-one": "6.0.0", "ml-regression-polynomial": "^3.0.0", diff --git a/packages/grafana-data/package.json b/packages/grafana-data/package.json index cd1105d0fe3..b3f42e49b21 100644 --- a/packages/grafana-data/package.json +++ b/packages/grafana-data/package.json @@ -46,7 +46,7 @@ "fast_array_intersect": "1.1.0", "history": "4.10.1", "lodash": "4.17.21", - "marked": "5.1.1", + "marked": "12.0.0", "marked-mangle": "1.1.7", "moment": "2.30.1", "moment-timezone": "0.5.45", diff --git a/packages/grafana-data/src/text/markdown.ts b/packages/grafana-data/src/text/markdown.ts index 3ddfd83b4df..446e95e6f82 100644 --- a/packages/grafana-data/src/text/markdown.ts +++ b/packages/grafana-data/src/text/markdown.ts @@ -1,4 +1,4 @@ -import { marked } from 'marked'; +import { marked, MarkedOptions } from 'marked'; import { mangle } from 'marked-mangle'; import { sanitizeTextPanelContent } from './sanitize'; @@ -10,13 +10,9 @@ export interface RenderMarkdownOptions { breaks?: boolean; } -const markdownOptions = { - headerIds: false, +const markdownOptions: MarkedOptions = { pedantic: false, gfm: true, - smartLists: true, - smartypants: false, - xhtml: false, breaks: false, }; @@ -36,6 +32,12 @@ export function renderMarkdown(str?: string, options?: RenderMarkdownOptions): s } const html = marked(str || '', opts); + // `marked()` returns a promise if using any extensions that require async processing. + // we don't use any async extensions, but there is no way for typescript to know this, so we need to check the type. + if (typeof html !== 'string') { + throw new Error('Failed to process markdown synchronously.'); + } + if (options?.noSanitize) { return html; } @@ -51,6 +53,13 @@ export function renderTextPanelMarkdown(str?: string, options?: RenderMarkdownOp } const html = marked(str || ''); + + // `marked()` returns a promise if using any extensions that require async processing. + // we don't use any async extensions, but there is no way for typescript to know this, so we need to check the type. + if (typeof html !== 'string') { + throw new Error('Failed to process markdown synchronously.'); + } + if (options?.noSanitize) { return html; } diff --git a/packages/grafana-prometheus/package.json b/packages/grafana-prometheus/package.json index 7c701a97efe..a139ca5e532 100644 --- a/packages/grafana-prometheus/package.json +++ b/packages/grafana-prometheus/package.json @@ -46,7 +46,7 @@ "eventemitter3": "5.0.1", "lodash": "4.17.21", "lru-cache": "10.2.0", - "marked": "5.1.1", + "marked": "12.0.0", "marked-mangle": "1.1.7", "moment": "2.30.1", "moment-timezone": "0.5.45", diff --git a/yarn.lock b/yarn.lock index e3240591b4c..7a319705b54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3540,7 +3540,7 @@ __metadata: fast_array_intersect: "npm:1.1.0" history: "npm:4.10.1" lodash: "npm:4.17.21" - marked: "npm:5.1.1" + marked: "npm:12.0.0" marked-mangle: "npm:1.1.7" moment: "npm:2.30.1" moment-timezone: "npm:0.5.45" @@ -3957,7 +3957,7 @@ __metadata: jest-matcher-utils: "npm:29.7.0" lodash: "npm:4.17.21" lru-cache: "npm:10.2.0" - marked: "npm:5.1.1" + marked: "npm:12.0.0" marked-mangle: "npm:1.1.7" moment: "npm:2.30.1" moment-timezone: "npm:0.5.45" @@ -18371,7 +18371,7 @@ __metadata: lru-cache: "npm:10.2.0" lru-memoize: "npm:^1.1.0" lucene: "npm:^2.1.1" - marked: "npm:5.1.1" + marked: "npm:12.0.0" marked-mangle: "npm:1.1.7" memoize-one: "npm:6.0.0" mini-css-extract-plugin: "npm:2.8.0" @@ -22104,12 +22104,12 @@ __metadata: languageName: node linkType: hard -"marked@npm:5.1.1": - version: 5.1.1 - resolution: "marked@npm:5.1.1" +"marked@npm:12.0.0": + version: 12.0.0 + resolution: "marked@npm:12.0.0" bin: marked: bin/marked.js - checksum: 10/88bf0b1db52a84222956bc32e7e7cc7b3ecc6a978ec37acafd4e45aeb6c1c5a62640ab570fc1fccbaf385d39b4783a41a2e1d71f2766cf905e32164dc74eeec5 + checksum: 10/ac2e5a3ebf33f8636e65c1eb7f73267cbe101fea1ad08abab60d51e5b4fda30faa59050e2837dc03fb6dbf58f630485c8d01ae5b9d90d36bf4562d7f40c1d33e languageName: node linkType: hard