-
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
Conversation
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.
Thanks @cdebarros for this first PR.
I need to wrap up the approach a bit with @jahow but as a first review, I would just point out that a component seems not appropriate for such a process.
I would have more seen a Pipe and/or a directive.
Also, I wonder if the css could be encapsulated somehow instead of being spread via the encapsulation: ViewEncapsulation.None
option.
What would be an argument for using a pipe or directive instead of a component? I'm still unsure which solution is the best personally. Using a component has the advantage that we can use an encapsulated style inside it. |
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.
Thanks for this contribution! I think this looks really good. I added a few comments, specifically to avoid disabling the view encapsulation; once addressed I think this can be merged. Please let me know if you need any more information!
@fgravin I've thought about it again and using a component seems right to me; please let us know if you have arguments against it
.markdown-body h1 { | ||
margin: 0.67em 0; | ||
font-weight: 600; | ||
padding-bottom: 0.3em; | ||
font-size: 2em; | ||
color: var(--color-primary); | ||
} |
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.
selector: 'gn-ui-markdown-parser', | ||
templateUrl: './markdown-parser.component.html', | ||
styleUrls: ['./markdown-parser.component.css'], | ||
encapsulation: ViewEncapsulation.None, |
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.
you can get rid of this and leave the default view encapsulation by adding :host /deep/
before all classes in the CSS file; this is a bit more verbose but IMO essential since disabling view encapsulation is risky in the long run
Note: Snyk workflow always fails for forks; please disregard that |
Thanks for your reviews ! |
I just updated my contribution. Added css encapsulation and storybook for the component. On the default storybook content, i explain which markdown elements are supported for now. |
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.
Thanks for the adaptations, I think this looks better now. There are choices in the styling of the output that might not fit for every occasion and theme, but for now we can keep it like that and see how it behaves in the "wild".
I realized there was no unit test, I missed that on the first review. Could you please add one that ensures that the input is processed into the div inner HTML?
Also the branch needs to be rebased; there will likely be a conflict because we added gnUiLinkify
on the abstract in the meantime; this directive can be removed from the abstract since marked
does the same thing :)
Thank you for your continued efforts
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) |
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 :
- 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.
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 🙂
@Component({ | ||
selector: 'gn-ui-markdown-parser', | ||
templateUrl: './markdown-parser.component.html', | ||
styleUrls: ['./markdown-parser.component.css'], |
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.
I also forgot to point out that we should always use changeDetection: ChangeDetectionStrategy.OnPush,
to make sure that the change detection does not run too often
a784302
to
0b93325
Compare
I added tests and the changeDetectionStrategy to the component. Also i rebased the branch. |
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.
Thanks for this great contribution! There is a failure on the build attempts in the CI, to fix it you can bump the CSS budgets for all apps like so:
diff --git a/apps/datafeeder/project.json b/apps/datafeeder/project.json
index 67998c55..b22bc758 100644
--- a/apps/datafeeder/project.json
+++ b/apps/datafeeder/project.json
@@ -40,8 +40,8 @@
},
{
"type": "anyComponentStyle",
- "maximumWarning": "2kb",
- "maximumError": "4kb"
+ "maximumWarning": "10kb",
+ "maximumError": "20kb"
}
],
"fileReplacements": [
I updated it for the 3 projects that have failed, it should be fine now. Is there a way to remove warnings from the css file ? (there is the same warning in the carousel component) |
Don't worry about the CSS warnings, I'll fix them in another PR. Thank you again for this awesome contribution, congratulations on it and we're looking forward to more of this!! 🎉 |
Hi, first of all happy new year to everyone seeing this. Here is my first contribution to the project.
This pull request makes the following changes :
I used
marked
to parse markdown content to html and then i defined some basic style for the following elements as suggested by @jahow :I tried to use tailwind base colors to make it close to the default style.
I'm not sure how should i render links, blockquotes or table. I'll wait for your feedbacks to make some changes if needed.