Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ui element markdown-parser and markdown support on metadata… #746

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/map-viewer/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
"maximumError": "5kb"
}
],
"fileReplacements": [
Expand Down
2 changes: 1 addition & 1 deletion apps/metadata-editor/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
"maximumError": "5kb"
}
],
"outputHashing": "all"
Expand Down
2 changes: 1 addition & 1 deletion apps/search/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
"maximumError": "5kb"
}
],
"fileReplacements": [
Expand Down
1 change: 1 addition & 0 deletions libs/ui/elements/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +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'
264 changes: 264 additions & 0 deletions libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
/** Body **/
:host /deep/ .markdown-body {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
margin: 0px 0px 1.5rem 0px;
line-height: 1.5;
word-wrap: break-word;
}

/** Emphasis **/

:host /deep/ .markdown-body strong {
@apply font-bold;
color: var(--color-secondary-darker);
}

/** Headings **/

: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;
line-height: 1.25;
@apply text-title font-title font-bold;
}

:host /deep/ .markdown-body h1 {
margin: 0.67em 0;
padding-bottom: 0.3em;
font-size: 2em;
color: var(--color-primary);
}

:host /deep/ .markdown-body h2 {
padding-bottom: 0.3em;
font-size: 1.5em;
color: var(--color-secondary);
}

:host /deep/ .markdown-body h3 {
font-size: 1.25em;
color: var(--color-secondary);
}

:host /deep/ .markdown-body h4 {
font-size: 1em;
color: var(--color-secondary);
}

:host /deep/ .markdown-body h5 {
font-size: 0.875em;
color: var(--color-secondary);
}

:host /deep/ .markdown-body h6 {
font-size: 0.85em;
color: var(--color-secondary-lighter);
}

/** Paragraphs **/

:host /deep/ .markdown-body p {
margin-top: 0;
margin-bottom: 10px;
}

/** Links **/

:host /deep/ .markdown-body p > a {
margin-top: 0;
margin-bottom: 10px;
color: var(--color-primary) !important;
text-decoration: none !important;
@apply font-bold;
}

:host /deep/ .markdown-body p > a:hover {
color: var(--color-primary-darker) !important;
}

/** Blockquotes **/

:host /deep/ .markdown-body blockquote {
margin: 0;
padding: 0 1em;
color: var(--color-secondary-lighter);
border-left: 0.25em solid var(--color-primary-lighter);
}

/** Code **/

:host /deep/ .markdown-body pre {
margin-top: 0;
margin-bottom: 0;
font-size: 12px;
background-color: var(--color-gray-100);
word-wrap: normal;
}

:host /deep/ .markdown-body pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
color: var(--color-secondary);
border-radius: 6px;
}

:host /deep/ .markdown-body code {
padding: 0.2em 0.4em;
margin: 0;
font-size: 85%;
white-space: break-spaces;
border-radius: 6px;
}

:host /deep/ .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 **/

:host /deep/ .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;
}

:host /deep/ .markdown-body hr::before {
display: table;
content: '';
}

:host /deep/ .markdown-body hr::after {
display: table;
clear: both;
content: '';
}

/** Lists **/

:host /deep/ .markdown-body ul,
:host /deep/ .markdown-body ol {
margin-top: 0;
margin-bottom: 0;
padding-left: 2em;
list-style: revert;
}

:host /deep/ .markdown-body ol ol,
:host /deep/ .markdown-body ul ol {
list-style-type: lower-roman;
}

: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;
}

:host /deep/ .markdown-body ol[type='a s'] {
list-style-type: lower-alpha;
}

:host /deep/ .markdown-body ol[type='A s'] {
list-style-type: upper-alpha;
}

:host /deep/ .markdown-body ol[type='i s'] {
list-style-type: lower-roman;
}

:host /deep/ .markdown-body ol[type='I s'] {
list-style-type: upper-roman;
}

:host /deep/ .markdown-body ol[type='1'] {
list-style: unset;
list-style-type: decimal;
}

:host /deep/ .markdown-body div > ol:not([type]) {
list-style: unset;
list-style-type: decimal;
}

/** 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;
}

:host /deep/ .markdown-body td,
:host /deep/ .markdown-body th {
padding: 0;
}

:host /deep/ .markdown-body th {
color: var(--color-secondary);
}

:host /deep/ .markdown-body table th,
:host /deep/ .markdown-body table td {
padding: 6px 13px;
border: 1px solid var(--color-gray-500);
}

:host /deep/ .markdown-body table td > :last-child {
margin-bottom: 0;
}

:host /deep/ .markdown-body table tr {
background-color: #ffffff;
border-top: 1px solid var(--color-secondary-lighter);
}

:host /deep/ .markdown-body table tr:nth-child(2n) {
background-color: var(--color-gray-100);
}

:host /deep/ .markdown-body table img {
background-color: transparent;
}

/** Images **/

:host /deep/ .markdown-body img {
border-style: none;
max-width: 100%;
box-sizing: content-box;
background-color: transparent;
}

:host /deep/ .markdown-body img[align='right'] {
padding-left: 20px;
}

:host /deep/ .markdown-body img[align='left'] {
padding-right: 20px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="markdown-body" [innerHTML]="parsedMarkdown"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { MarkdownParserComponent } from './markdown-parser.component'

describe('MarkdownParserComponent', () => {
let component: MarkdownParserComponent
let fixture: ComponentFixture<MarkdownParserComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MarkdownParserComponent],
}).compileComponents()

fixture = TestBed.createComponent(MarkdownParserComponent)
component = fixture.componentInstance
})

it('should create', () => {
expect(component).toBeTruthy()
})
Copy link
Collaborator

@jahow jahow Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I didn't realize that in the first review but we need at least one test here, showing that a markdown input will be correctly transformed to HTML; this doesn't have to be exhaustive as we're not testing the underlying library, but simply making sure that the input is processed.

Could you please add that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, i totally forgot about that.

I created 3 tests described like this :

  • should render markdown as HTML
  • should render HTML as HTML
  • should render text as HTML

Is it too much ? Maybe the first test is enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does look like a perfect amount of tests 🙂


it('should render markdown as HTML', () => {
component.textContent = '**bold markdown**'
fixture.detectChanges()
const markdown = fixture.nativeElement.innerHTML
expect(markdown).toContain('<p><strong>bold markdown</strong></p>')
})

it('should render HTML as HTML', () => {
component.textContent = '<p><strong>simple html</strong></p>'
fixture.detectChanges()
const html = fixture.nativeElement.innerHTML
expect(html).toContain('<p><strong>simple html</strong></p>')
})

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