From 2e4fa87a3eec813feeb06ff927ff1c381fff8497 Mon Sep 17 00:00:00 2001 From: cde-barros Date: Tue, 2 Jan 2024 13:47:32 +0100 Subject: [PATCH 1/4] [add] the ui element markdown-parser and markdown support on metadata-info --- libs/ui/elements/src/index.ts | 2 + .../markdown-parser.component.css | 271 ++++++++++++++++++ .../markdown-parser.component.html | 1 + .../markdown-parser.component.spec.ts | 21 ++ .../markdown-parser.component.ts | 16 ++ .../metadata-info.component.html | 8 +- .../ui/elements/src/lib/ui-elements.module.ts | 3 + package-lock.json | 12 + package.json | 1 + 9 files changed, 330 insertions(+), 5 deletions(-) create mode 100644 libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css create mode 100644 libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.html create mode 100644 libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts create mode 100644 libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts diff --git a/libs/ui/elements/src/index.ts b/libs/ui/elements/src/index.ts index 61cb50dd29..eb86a51913 100644 --- a/libs/ui/elements/src/index.ts +++ b/libs/ui/elements/src/index.ts @@ -19,3 +19,5 @@ export * from './lib/related-record-card/related-record-card.component' export * from './lib/search-results-error/search-results-error.component' export * from './lib/user-preview/user-preview.component' export * from './lib/record-api-form/record-api-form.component' + +export * from './lib/markdown-parser/markdown-parser.component' diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css new file mode 100644 index 0000000000..073b980cf5 --- /dev/null +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css @@ -0,0 +1,271 @@ +/** Body **/ +.markdown-body { + -ms-text-size-adjust: 100%; + -webkit-text-size-adjust: 100%; + margin: 0px 0px 1.5rem 0px; + color: var(--color-main); + font-size: 16px; + line-height: 1.5; + word-wrap: break-word; +} + +/** Emphasis **/ + +.markdown-body strong { + font-weight: 600; + color: var(--color-secondary-darker); +} + +/** Headings **/ + +.markdown-body h1, +.markdown-body h2, +.markdown-body h3, +.markdown-body h4, +.markdown-body h5, +.markdown-body h6 { + margin-top: 24px; + margin-bottom: 16px; + font-weight: 600; + line-height: 1.25; +} + +.markdown-body h1 { + margin: 0.67em 0; + font-weight: 600; + padding-bottom: 0.3em; + font-size: 2em; + color: var(--color-primary); +} + +.markdown-body h2 { + font-weight: 600; + padding-bottom: 0.3em; + font-size: 1.5em; + color: var(--color-secondary); +} + +.markdown-body h3 { + font-weight: 600; + font-size: 1.25em; + color: var(--color-secondary); +} + +.markdown-body h4 { + font-weight: 600; + font-size: 1em; + color: var(--color-secondary); +} + +.markdown-body h5 { + font-weight: 600; + font-size: 0.875em; + color: var(--color-secondary); +} + +.markdown-body h6 { + font-weight: 600; + font-size: 0.85em; + color: var(--color-secondary-lighter); +} + +/** Paragraphs **/ + +.markdown-body p { + margin-top: 0; + margin-bottom: 10px; +} + +/** Links **/ + +.markdown-body p > a { + margin-top: 0; + margin-bottom: 10px; + color: var(--color-primary) !important; + text-decoration: none !important; + font-weight: 600; +} + +.markdown-body p > a:hover { + color: var(--color-primary-darker) !important; +} + +/** Blockquotes **/ + +.markdown-body blockquote { + margin: 0; + padding: 0 1em; + color: var(--color-secondary-lighter); + border-left: 0.25em solid var(--color-primary-lighter); +} + +/** Code **/ + +.markdown-body pre { + margin-top: 0; + margin-bottom: 0; + font-size: 12px; + background-color: var(--color-gray-100); + word-wrap: normal; +} + +.markdown-body pre { + padding: 16px; + overflow: auto; + font-size: 85%; + line-height: 1.45; + color: var(--color-secondary); + border-radius: 6px; +} + +.markdown-body code { + padding: 0.2em 0.4em; + margin: 0; + font-size: 85%; + white-space: break-spaces; + border-radius: 6px; +} + +.markdown-body pre code { + display: inline; + max-width: auto; + padding: 0; + margin: 0; + overflow: visible; + line-height: inherit; + word-wrap: normal; + border: 0; +} + +/** Horizontal rules **/ + +.markdown-body hr { + box-sizing: content-box; + overflow: hidden; + background: transparent; + border-bottom: 1px solid var(--color-secondary); + height: 0.15em; + padding: 0; + margin: 24px 0; + background-color: var(--color-secondary); + border: 0; +} + +.markdown-body hr::before { + display: table; + content: ''; +} + +.markdown-body hr::after { + display: table; + clear: both; + content: ''; +} + +/** Lists **/ + +.markdown-body ul, +.markdown-body ol { + margin-top: 0; + margin-bottom: 0; + padding-left: 2em; + list-style: revert; +} + +.markdown-body ol ol, +.markdown-body ul ol { + list-style-type: lower-roman; +} + +.markdown-body ul ul ol, +.markdown-body ul ol ol, +.markdown-body ol ul ol, +.markdown-body ol ol ol { + list-style-type: lower-alpha; +} + +.markdown-body ol[type='a s'] { + list-style-type: lower-alpha; +} + +.markdown-body ol[type='A s'] { + list-style-type: upper-alpha; +} + +.markdown-body ol[type='i s'] { + list-style-type: lower-roman; +} + +.markdown-body ol[type='I s'] { + list-style-type: upper-roman; +} + +.markdown-body ol[type='1'] { + list-style: unset; + list-style-type: decimal; +} + +.markdown-body div > ol:not([type]) { + list-style: unset; + list-style-type: decimal; +} + +/** Table **/ + +.markdown-body table { + border-spacing: 0; + border-collapse: collapse; + display: block; + width: max-content; + max-width: 100%; + overflow: auto; +} + +.markdown-body td, +.markdown-body th { + padding: 0; +} + +.markdown-body th { + color: var(--color-secondary); +} + +.markdown-body table th, +.markdown-body table td { + padding: 6px 13px; + border: 1px solid var(--color-gray-500); +} + +.markdown-body table td > :last-child { + margin-bottom: 0; +} + +.markdown-body table tr { + background-color: #ffffff; + border-top: 1px solid var(--color-secondary-lighter); +} + +.markdown-body table tr:nth-child(2n) { + background-color: var(--color-gray-100); +} + +.markdown-body table img { + background-color: transparent; +} + +/** Images **/ + +.markdown-body img { + border-style: none; + max-width: 100%; + box-sizing: content-box; + background-color: transparent; +} + +.markdown-body img[align='right'] { + padding-left: 20px; +} + +.markdown-body img[align='left'] { + padding-right: 20px; +} diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.html b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.html new file mode 100644 index 0000000000..93f466a59a --- /dev/null +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.html @@ -0,0 +1 @@ +
diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts new file mode 100644 index 0000000000..59e3be62e3 --- /dev/null +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { MarkdownParserComponent } from './markdown-parser.component' + +describe('MarkdownParserComponent', () => { + let component: MarkdownParserComponent + let fixture: ComponentFixture + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [MarkdownParserComponent], + }).compileComponents() + + fixture = TestBed.createComponent(MarkdownParserComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) + + it('should create', () => { + expect(component).toBeTruthy() + }) +}) diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts new file mode 100644 index 0000000000..d423a27939 --- /dev/null +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts @@ -0,0 +1,16 @@ +import { Component, Input, ViewEncapsulation } from '@angular/core' +import { marked } from 'marked' + +@Component({ + selector: 'gn-ui-markdown-parser', + templateUrl: './markdown-parser.component.html', + styleUrls: ['./markdown-parser.component.css'], + encapsulation: ViewEncapsulation.None, +}) +export class MarkdownParserComponent { + @Input() textContent: string + + get parsedMarkdown() { + return marked.parse(this.textContent) + } +} diff --git a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html index 369eff7235..fa13aae0ba 100644 --- a/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html +++ b/libs/ui/elements/src/lib/metadata-info/metadata-info.component.html @@ -8,11 +8,9 @@
-

+

record.metadata.keywords diff --git a/libs/ui/elements/src/lib/ui-elements.module.ts b/libs/ui/elements/src/lib/ui-elements.module.ts index 73b00327a2..eac4060e3b 100644 --- a/libs/ui/elements/src/lib/ui-elements.module.ts +++ b/libs/ui/elements/src/lib/ui-elements.module.ts @@ -29,6 +29,7 @@ import { GnUiLinkifyDirective } from './metadata-info/linkify.directive' import { PaginationButtonsComponent } from './pagination-buttons/pagination-buttons.component' import { MaxLinesComponent } from './max-lines/max-lines.component' import { RecordApiFormComponent } from './record-api-form/record-api-form.component' +import { MarkdownParserComponent } from './markdown-parser/markdown-parser.component' @NgModule({ imports: [ @@ -65,6 +66,7 @@ import { RecordApiFormComponent } from './record-api-form/record-api-form.compon PaginationButtonsComponent, MaxLinesComponent, RecordApiFormComponent, + MarkdownParserComponent, ], exports: [ MetadataInfoComponent, @@ -85,6 +87,7 @@ import { RecordApiFormComponent } from './record-api-form/record-api-form.compon UserPreviewComponent, PaginationButtonsComponent, RecordApiFormComponent, + MarkdownParserComponent, ], }) export class UiElementsModule {} diff --git a/package-lock.json b/package-lock.json index ff2f2588b7..e1d431a51d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,6 +50,7 @@ "embla-carousel": "^8.0.0-rc14", "express": "^4.17.1", "geojson-validation": "^1.0.2", + "marked": "^11.1.1", "moment": "^2.29.4", "ng-table-virtual-scroll": "^1.4.1", "ngx-chips": "3.0.0", @@ -23997,6 +23998,17 @@ "react": ">= 0.14.0" } }, + "node_modules/marked": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-11.1.1.tgz", + "integrity": "sha512-EgxRjgK9axsQuUa/oKMx5DEY8oXpKJfk61rT5iY3aRlgU6QJtUcxU5OAymdhCvWvhYcd9FKmO5eQoX8m9VGJXg==", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/mdast-util-definitions": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/mdast-util-definitions/-/mdast-util-definitions-4.0.0.tgz", diff --git a/package.json b/package.json index d7589bf7cd..7c3bde2dd8 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "embla-carousel": "^8.0.0-rc14", "express": "^4.17.1", "geojson-validation": "^1.0.2", + "marked": "^11.1.1", "moment": "^2.29.4", "ng-table-virtual-scroll": "^1.4.1", "ngx-chips": "3.0.0", From 33659321ceb68cae983f156eca046adff73ea3d7 Mon Sep 17 00:00:00 2001 From: cde-barros Date: Tue, 16 Jan 2024 11:35:09 +0100 Subject: [PATCH 2/4] Css is now encapsulated and storybook added for the component --- libs/ui/elements/src/index.ts | 1 - .../markdown-parser.component.css | 119 +++++++------- .../markdown-parser.component.stories.ts | 148 ++++++++++++++++++ .../markdown-parser.component.ts | 3 +- 4 files changed, 205 insertions(+), 66 deletions(-) create mode 100644 libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.stories.ts diff --git a/libs/ui/elements/src/index.ts b/libs/ui/elements/src/index.ts index eb86a51913..ed3b7f3ad5 100644 --- a/libs/ui/elements/src/index.ts +++ b/libs/ui/elements/src/index.ts @@ -19,5 +19,4 @@ export * from './lib/related-record-card/related-record-card.component' export * from './lib/search-results-error/search-results-error.component' export * from './lib/user-preview/user-preview.component' export * from './lib/record-api-form/record-api-form.component' - export * from './lib/markdown-parser/markdown-parser.component' diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css index 073b980cf5..36dcdc95d6 100644 --- a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css @@ -1,98 +1,90 @@ /** Body **/ -.markdown-body { +:host /deep/ .markdown-body { -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; margin: 0px 0px 1.5rem 0px; - color: var(--color-main); - font-size: 16px; line-height: 1.5; word-wrap: break-word; } /** Emphasis **/ -.markdown-body strong { - font-weight: 600; +:host /deep/ .markdown-body strong { + @apply font-bold; color: var(--color-secondary-darker); } /** Headings **/ -.markdown-body h1, -.markdown-body h2, -.markdown-body h3, -.markdown-body h4, -.markdown-body h5, -.markdown-body h6 { +:host /deep/ .markdown-body h1, +:host /deep/ .markdown-body h2, +:host /deep/ .markdown-body h3, +:host /deep/ .markdown-body h4, +:host /deep/ .markdown-body h5, +:host /deep/ .markdown-body h6 { margin-top: 24px; margin-bottom: 16px; - font-weight: 600; line-height: 1.25; + @apply text-title font-title font-bold; } -.markdown-body h1 { +:host /deep/ .markdown-body h1 { margin: 0.67em 0; - font-weight: 600; padding-bottom: 0.3em; font-size: 2em; color: var(--color-primary); } -.markdown-body h2 { - font-weight: 600; +:host /deep/ .markdown-body h2 { padding-bottom: 0.3em; font-size: 1.5em; color: var(--color-secondary); } -.markdown-body h3 { - font-weight: 600; +:host /deep/ .markdown-body h3 { font-size: 1.25em; color: var(--color-secondary); } -.markdown-body h4 { - font-weight: 600; +:host /deep/ .markdown-body h4 { font-size: 1em; color: var(--color-secondary); } -.markdown-body h5 { - font-weight: 600; +:host /deep/ .markdown-body h5 { font-size: 0.875em; color: var(--color-secondary); } -.markdown-body h6 { - font-weight: 600; +:host /deep/ .markdown-body h6 { font-size: 0.85em; color: var(--color-secondary-lighter); } /** Paragraphs **/ -.markdown-body p { +:host /deep/ .markdown-body p { margin-top: 0; margin-bottom: 10px; } /** Links **/ -.markdown-body p > a { +:host /deep/ .markdown-body p > a { margin-top: 0; margin-bottom: 10px; color: var(--color-primary) !important; text-decoration: none !important; - font-weight: 600; + @apply font-bold; } -.markdown-body p > a:hover { +:host /deep/ .markdown-body p > a:hover { color: var(--color-primary-darker) !important; } /** Blockquotes **/ -.markdown-body blockquote { +:host /deep/ .markdown-body blockquote { margin: 0; padding: 0 1em; color: var(--color-secondary-lighter); @@ -101,7 +93,7 @@ /** Code **/ -.markdown-body pre { +:host /deep/ .markdown-body pre { margin-top: 0; margin-bottom: 0; font-size: 12px; @@ -109,7 +101,7 @@ word-wrap: normal; } -.markdown-body pre { +:host /deep/ .markdown-body pre { padding: 16px; overflow: auto; font-size: 85%; @@ -118,7 +110,7 @@ border-radius: 6px; } -.markdown-body code { +:host /deep/ .markdown-body code { padding: 0.2em 0.4em; margin: 0; font-size: 85%; @@ -126,7 +118,7 @@ border-radius: 6px; } -.markdown-body pre code { +:host /deep/ .markdown-body pre code { display: inline; max-width: auto; padding: 0; @@ -139,7 +131,7 @@ /** Horizontal rules **/ -.markdown-body hr { +:host /deep/ .markdown-body hr { box-sizing: content-box; overflow: hidden; background: transparent; @@ -151,12 +143,12 @@ border: 0; } -.markdown-body hr::before { +:host /deep/ .markdown-body hr::before { display: table; content: ''; } -.markdown-body hr::after { +:host /deep/ .markdown-body hr::after { display: table; clear: both; content: ''; @@ -164,108 +156,109 @@ /** Lists **/ -.markdown-body ul, -.markdown-body ol { +:host /deep/ .markdown-body ul, +:host /deep/ .markdown-body ol { margin-top: 0; margin-bottom: 0; padding-left: 2em; list-style: revert; } -.markdown-body ol ol, -.markdown-body ul ol { +:host /deep/ .markdown-body ol ol, +:host /deep/ .markdown-body ul ol { list-style-type: lower-roman; } -.markdown-body ul ul ol, -.markdown-body ul ol ol, -.markdown-body ol ul ol, -.markdown-body ol ol ol { +:host /deep/ .markdown-body ul ul ol, +:host /deep/ .markdown-body ul ol ol, +:host /deep/ .markdown-body ol ul ol, +:host /deep/ .markdown-body ol ol ol { list-style-type: lower-alpha; } -.markdown-body ol[type='a s'] { +:host /deep/ .markdown-body ol[type='a s'] { list-style-type: lower-alpha; } -.markdown-body ol[type='A s'] { +:host /deep/ .markdown-body ol[type='A s'] { list-style-type: upper-alpha; } -.markdown-body ol[type='i s'] { +:host /deep/ .markdown-body ol[type='i s'] { list-style-type: lower-roman; } -.markdown-body ol[type='I s'] { +:host /deep/ .markdown-body ol[type='I s'] { list-style-type: upper-roman; } -.markdown-body ol[type='1'] { +:host /deep/ .markdown-body ol[type='1'] { list-style: unset; list-style-type: decimal; } -.markdown-body div > ol:not([type]) { +:host /deep/ .markdown-body div > ol:not([type]) { list-style: unset; list-style-type: decimal; } /** Table **/ -.markdown-body table { +:host /deep/ .markdown-body table { border-spacing: 0; border-collapse: collapse; display: block; width: max-content; max-width: 100%; overflow: auto; + padding-bottom: 15px; } -.markdown-body td, -.markdown-body th { +:host /deep/ .markdown-body td, +:host /deep/ .markdown-body th { padding: 0; } -.markdown-body th { +:host /deep/ .markdown-body th { color: var(--color-secondary); } -.markdown-body table th, -.markdown-body table td { +:host /deep/ .markdown-body table th, +:host /deep/ .markdown-body table td { padding: 6px 13px; border: 1px solid var(--color-gray-500); } -.markdown-body table td > :last-child { +:host /deep/ .markdown-body table td > :last-child { margin-bottom: 0; } -.markdown-body table tr { +:host /deep/ .markdown-body table tr { background-color: #ffffff; border-top: 1px solid var(--color-secondary-lighter); } -.markdown-body table tr:nth-child(2n) { +:host /deep/ .markdown-body table tr:nth-child(2n) { background-color: var(--color-gray-100); } -.markdown-body table img { +:host /deep/ .markdown-body table img { background-color: transparent; } /** Images **/ -.markdown-body img { +:host /deep/ .markdown-body img { border-style: none; max-width: 100%; box-sizing: content-box; background-color: transparent; } -.markdown-body img[align='right'] { +:host /deep/ .markdown-body img[align='right'] { padding-left: 20px; } -.markdown-body img[align='left'] { +:host /deep/ .markdown-body img[align='left'] { padding-right: 20px; } diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.stories.ts b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.stories.ts new file mode 100644 index 0000000000..b7664783e7 --- /dev/null +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.stories.ts @@ -0,0 +1,148 @@ +import { Meta, moduleMetadata, StoryObj } from '@storybook/angular' +import { MarkdownParserComponent } from './markdown-parser.component' + +export default { + title: 'Elements/MarkdownParserComponent', + component: MarkdownParserComponent, + decorators: [ + moduleMetadata({ + declarations: [MarkdownParserComponent], + }), + ], +} as Meta + +export const Primary: StoryObj = { + args: { + textContent: ` +# SUPPORTED MARKDOWN CONTENT + +## 1) Headings + ++ # h1 Heading ++ ## h2 Heading ++ ### h3 Heading ++ #### h4 Heading ++ ##### h5 Heading ++ ###### h6 Heading + + +## 2) Horizontal Rules + ++ ___ + ++ --- + ++ *** + +## 3) Emphasis + ++ **This is bold text** + ++ __This is bold text__ + ++ *This is italic text* + ++ _This is italic text_ + ++ ~~Strikethrough~~ + + +## 3) Blockquotes + + +> Blockquotes can also be nested... +>> ...by using additional greater-than signs right next to each other... +> > > ...or with spaces between arrows. + + +## 4) Lists + +**Unordered** + ++ Create a list by starting a line with +, -, or * ++ Sub-lists are made by indenting 2 spaces: + - Marker character change forces new list start: + * Ac tristique libero volutpat at + + Facilisis in pretium nisl aliquet + - Nulla volutpat aliquam velit ++ List continue here + +**Ordered** + +1. Lorem ipsum dolor sit amet +2. Consectetur adipiscing elit +3. Integer molestie lorem at massa + + +1. You can use sequential numbers... +1. ...or keep all the numbers as 1. + +**Start numbering with offset:** + +57. foo +1. bar + + +## 5) Code + +**Inline code** + +(no example) + +**Indented code** + + // Some comments + line 1 of code + line 2 of code + line 3 of code + + +**Block code "fences"** + +(no example) + + +## 6) Tables + +**Left aligned columns** + +| Option | Description | +| ------ | ----------- | +| data | path to data files to supply the data that will be passed into templates. | +| engine | engine to be used for processing templates. Handlebars is the default. | +| ext | extension to be used for dest files. | + +**Right aligned columns** + +| Option | Description | +| ------:| -----------:| +| data | path to data files to supply the data that will be passed into templates. | +| engine | engine to be used for processing templates. Handlebars is the default. | +| ext | extension to be used for dest files. | + + +## 7) Links + +[link text](https://github.com/geonetwork/geonetwork-ui) + +[link with title](https://github.com/geonetwork/geonetwork-ui "title text!") + + +## 8) Images + +**With and without title** + +![Geonetwork](https://geonetwork-opensource.org/_static/chrome/geonetwork3-logo.png "Geonetwork title")`, + }, + argTypes: { + textContent: { + control: 'text', + }, + }, + render: (args) => ({ + props: args, + template: ``, + }), +} diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts index d423a27939..a4fbf0c1a8 100644 --- a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts @@ -1,11 +1,10 @@ -import { Component, Input, ViewEncapsulation } from '@angular/core' +import { Component, Input } from '@angular/core' import { marked } from 'marked' @Component({ selector: 'gn-ui-markdown-parser', templateUrl: './markdown-parser.component.html', styleUrls: ['./markdown-parser.component.css'], - encapsulation: ViewEncapsulation.None, }) export class MarkdownParserComponent { @Input() textContent: string From 0b933257bf9ab5d200af61ef79ac4a71c0ad8d2d Mon Sep 17 00:00:00 2001 From: cde-barros Date: Wed, 17 Jan 2024 15:54:25 +0100 Subject: [PATCH 3/4] add testing and changeDirectionStrategy --- .../markdown-parser.component.spec.ts | 22 ++++++++++++++++++- .../markdown-parser.component.ts | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts index 59e3be62e3..d8534a7bfc 100644 --- a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts @@ -12,10 +12,30 @@ describe('MarkdownParserComponent', () => { fixture = TestBed.createComponent(MarkdownParserComponent) component = fixture.componentInstance - fixture.detectChanges() }) it('should create', () => { expect(component).toBeTruthy() }) + + it('should render markdown as HTML', () => { + component.textContent = '**bold markdown**' + fixture.detectChanges() + const markdown = fixture.nativeElement.innerHTML + expect(markdown).toContain('

bold markdown

') + }) + + it('should render HTML as HTML', () => { + component.textContent = '

simple html

' + fixture.detectChanges() + const html = fixture.nativeElement.innerHTML + expect(html).toContain('

simple html

') + }) + + it('should render text as HTML', () => { + component.textContent = 'simple text' + fixture.detectChanges() + const text = fixture.nativeElement.innerHTML + expect(text).toContain('

simple text

') + }) }) diff --git a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts index a4fbf0c1a8..679462caf8 100644 --- a/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts +++ b/libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.ts @@ -1,10 +1,11 @@ -import { Component, Input } from '@angular/core' +import { Component, Input, ChangeDetectionStrategy } from '@angular/core' import { marked } from 'marked' @Component({ selector: 'gn-ui-markdown-parser', templateUrl: './markdown-parser.component.html', styleUrls: ['./markdown-parser.component.css'], + changeDetection: ChangeDetectionStrategy.OnPush, }) export class MarkdownParserComponent { @Input() textContent: string From 17da947f718cb4b2c28f6595f3f6fbaf225df212 Mon Sep 17 00:00:00 2001 From: cde-barros Date: Thu, 18 Jan 2024 10:36:15 +0100 Subject: [PATCH 4/4] update file size limit for components --- apps/map-viewer/project.json | 2 +- apps/metadata-editor/project.json | 2 +- apps/search/project.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/map-viewer/project.json b/apps/map-viewer/project.json index 0ccb1c8bef..a7fade28af 100644 --- a/apps/map-viewer/project.json +++ b/apps/map-viewer/project.json @@ -42,7 +42,7 @@ { "type": "anyComponentStyle", "maximumWarning": "2kb", - "maximumError": "4kb" + "maximumError": "5kb" } ], "fileReplacements": [ diff --git a/apps/metadata-editor/project.json b/apps/metadata-editor/project.json index e93f92e72b..e38fcc319a 100644 --- a/apps/metadata-editor/project.json +++ b/apps/metadata-editor/project.json @@ -52,7 +52,7 @@ { "type": "anyComponentStyle", "maximumWarning": "2kb", - "maximumError": "4kb" + "maximumError": "5kb" } ], "outputHashing": "all" diff --git a/apps/search/project.json b/apps/search/project.json index 0fdf04538b..ff98cad88b 100644 --- a/apps/search/project.json +++ b/apps/search/project.json @@ -33,7 +33,7 @@ { "type": "anyComponentStyle", "maximumWarning": "2kb", - "maximumError": "4kb" + "maximumError": "5kb" } ], "fileReplacements": [