From 935c7451bde0db2abb869e9c0778b8d67af18274 Mon Sep 17 00:00:00 2001 From: Dusty Cartwright Date: Fri, 29 Apr 2022 08:11:50 -0700 Subject: [PATCH] update brand documentation site with new ucdlib-md component --- brand-app/components.js | 1 + brand-app/pages/page-ucdlib-md.js | 27 ++++++++++ brand-app/pages/page-ucdlib-md.tpl.js | 65 +++++++++++++++++++++++++ brand-app/ucdlib-theme-brand-app.tpl.js | 1 + 4 files changed, 94 insertions(+) create mode 100644 brand-app/pages/page-ucdlib-md.js create mode 100644 brand-app/pages/page-ucdlib-md.tpl.js diff --git a/brand-app/components.js b/brand-app/components.js index b38be08..3bc8e33 100644 --- a/brand-app/components.js +++ b/brand-app/components.js @@ -19,3 +19,4 @@ import "./pages/page-ucdlib-pages"; import "./pages/page-ucdlib-sils-permalink"; import "./pages/page-ucdlib-branding-bar"; import "./pages/page-ucdlib-sils-search-redirect"; +import "./pages/page-ucdlib-md"; \ No newline at end of file diff --git a/brand-app/pages/page-ucdlib-md.js b/brand-app/pages/page-ucdlib-md.js new file mode 100644 index 0000000..beeb56c --- /dev/null +++ b/brand-app/pages/page-ucdlib-md.js @@ -0,0 +1,27 @@ +import { LitElement } from 'lit'; +import {render, styles} from "./page-ucdlib-md.tpl.js"; + +import {Mixin, MainDomElement} from '../../elements/utils/mixins'; +import {BrandedPageElement, MdElement} from "../utils/index.js"; + +export default class PageUcdlibMd extends Mixin(LitElement) + .with(MainDomElement, BrandedPageElement, MdElement) { + + static get properties() { + return { + + }; + } + + static get styles() { + return styles(); + } + + constructor() { + super(); + this.render = render.bind(this); + } + +} + +customElements.define('page-ucdlib-md', PageUcdlibMd); \ No newline at end of file diff --git a/brand-app/pages/page-ucdlib-md.tpl.js b/brand-app/pages/page-ucdlib-md.tpl.js new file mode 100644 index 0000000..bab2782 --- /dev/null +++ b/brand-app/pages/page-ucdlib-md.tpl.js @@ -0,0 +1,65 @@ +import { html, css } from 'lit'; + +export function styles() { + const elementStyles = css` + :host { + display: block; + } + `; + + return [elementStyles]; +} + +export function render() { + return html` + ${this.pageTitle("Parse Markdown to HTML")} +

The ucdlib-md element parses Markdown text and renders HTML.

+ +

Using the component

+ +

There are a couple ways:

+ + ${this.examplePanel(html` + + + Enter your markdown here + ## h2 + > blockquote + **bold** text or *italicized* + - list + - etc + + + `, true)} + +

+ You can also omit the ucdlib-md-content element and instead use + the data property to set the markdown text. For instance,
+ document.querySelector('ucdlib-md').data = '## header content \n a paragraph with **bold** text.' +

+ +

Overriding the default renderer

+

+ It's also possible to override how some elements are rendered. Similar to the data property, set the + renderer property to an object holding the specific elements you'd like to override. +

+ + ${this.examplePanel(html` + document.querySelector('ucdlib-md').renderer = '{ + header(text, level) { + let renderedContent = ''; + if (level === 'h1') { + // something custom (ie custom class) + } else { + // combine h+level around text + } + return renderedContent; + } + // optionally other element types (comma-separated) + }' + `, true)} + +

The list of available element functions can be found on the Marked documentation page.

+ + `; +} diff --git a/brand-app/ucdlib-theme-brand-app.tpl.js b/brand-app/ucdlib-theme-brand-app.tpl.js index a56da36..4d28f13 100644 --- a/brand-app/ucdlib-theme-brand-app.tpl.js +++ b/brand-app/ucdlib-theme-brand-app.tpl.js @@ -86,6 +86,7 @@ return html`
  • Search Redirect
  • SILS Permalinks
  • +
  • Markdown