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

feat: Configurable Markup parsing and transformatin #7

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

renoirb
Copy link

@renoirb renoirb commented Jun 18, 2023

No description provided.

@renoirb renoirb force-pushed the renoirb/un-markup branch from e27fc48 to 1359165 Compare June 19, 2023 05:39
@renoirb
Copy link
Author

renoirb commented Jun 19, 2023

I've adjusted so the example works almost the same. Just the code colouring missing now.

@renoirb renoirb force-pushed the renoirb/un-markup branch from 1359165 to 6480188 Compare June 19, 2023 05:47
Copy link
Author

@renoirb renoirb left a comment

Choose a reason for hiding this comment

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

Notes from showcase convo I've had with Ben

<bt-time
class="published"
datetime="${resultDetails[result.ref].date}"
data-date-human-format="MMM D, YYYY"
Copy link
Author

Choose a reason for hiding this comment

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

Way to tell your own format

Comment on lines +99 to +112
_applyTransformedMarkup = (html = '') => {
const transformed = html !== ''
const elMarkupViewer = this.shadowRoot.querySelector('#markup-viewer')
const elTransformed = this.shadowRoot.querySelector(
'#markup-transformed',
)
if (transformed) {
elTransformed.innerHTML = html
elMarkupViewer.classList.remove('is-not-transformed')
elMarkupViewer.classList.add('is-transformed')
} else {
elTransformed.innerHTML = ''
elMarkupViewer.classList.add('is-not-transformed')
elMarkupViewer.classList.remove('is-transformed')
Copy link
Author

Choose a reason for hiding this comment

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

Apply replacing contents with parsed markdown without doing it. Let the component handle what to do, trust that the something else calling us back did do the markdown to HTML conversion.

Comment on lines +21 to +23
['bt-time', './bt-date-time.js'],
['bt-un-markup', './bt-un-markup.js'],
]
Copy link
Author

Choose a reason for hiding this comment

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

Provide default implementation of components to be registered (do not register them right away, allow people using us the ability to give us their implementation.

import { init } from './js/blogtini.js'

init(window, {
// Where we'll add customizations
Copy link
Author

Choose a reason for hiding this comment

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

(as if it was another site importing snd using blogtini)

That's where you define the components. Override bligtini's, and add your own that you plan on using in your markdown pages.

Comment on lines +17 to +24
export const assertIsValidCustomElementName = (
elementName /*: string */ = '',
) /*: assert is ... */ => {
if (/^[a-z]([\w\d-])+$/.test(elementName) === false) {
const message = `Invalid element name "${elementName}", it must only contain letters and dash.`
throw new Error(message)
}
}
Copy link
Author

Choose a reason for hiding this comment

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

There should be more component "interface" contract check. Done before registering. Or check in a different window realm. Check things like presence of slot names, attributes. So that if someone wants to override, we can check early if the component's compatible

TODO

Comment on lines +73 to +78
// TODO Make this configurable(?)
realm.document.addEventListener('context-request', (event) => {
// ... and others.
handleContextRequest_DateConversion(event)
handleContextRequest_TransformMarkup(event)
})
Copy link
Author

Choose a reason for hiding this comment

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

Define our implementation of context request response handler, but allow who's using us to override our fallback (TODO)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant