ngx-hackable-markdown
A customizable Markdown renderer wrapped in an Angular component.
- Template-driven -- accepts
ng-template
s overriding how HTML tags and entities are rendered. - Angular-Universal-friendly -- works with server-side rendering.
This is a 0.x.x version. Breaking API changes might come and bugs might occur!
Installation
npm install --save ngx-hackable-markdown
Example
my.module.ts
my.component.html
<!--styled spans surrouned by guillemets instead of strongs--> » « <!--blue triple bullets instead of ellipses--> • • • <!--heading IDs based on their text contents--> <!--custom buttons instead of links-->
Templating capabilities
The ngxHackableTag
directive should always adorn an ng-template
and accepts the following arguments:
- HTML tags:
a
,blockquote
,code
,del
,em
,h1
,h2
,h3
,h4
,h5
,h6
,hr
,img
,li
,ol
,p
,pre
,strong
,ul
. - HTML entities:
ndash
(rendered from--
),mdash
(rendered from---
),hellip
(rendered from...
).
The view-nesting [ngxHackableChildren]
directive adorning an ng-container
can (and usually should) be used inside templates for all HTML tags except hr
and img
.
The following view context properties can be used in templates (see the example above):
content
-- the object's recursive text content.metadata
-- an array of metadata like URL, title, etc. Exposed ina
andimg
templates. E.g.[foo](bar "baz plox")
yields['bar', 'baz plox']
children
-- a reference to the given node's children that should be passed to the[ngxHackableChildren]
directive.
See this cheat-sheet (or inspect rendered DOM) in case of uncertainty about which Markdown syntax maps to a given tag.