-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2e4fa87
[add] the ui element markdown-parser and markdown support on metadata…
cdebarros 3365932
Css is now encapsulated and storybook added for the component
cdebarros 0b93325
add testing and changeDirectionStrategy
cdebarros 17da947
update file size limit for components
cdebarros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
264 changes: 264 additions & 0 deletions
264
libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
1 change: 1 addition & 0 deletions
1
libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="markdown-body" [innerHTML]="parsedMarkdown"></div> |
41 changes: 41 additions & 0 deletions
41
libs/ui/elements/src/lib/markdown-parser/markdown-parser.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
|
||
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>') | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :
Is it too much ? Maybe the first test is enough.
There was a problem hiding this comment.
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 🙂