-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
Codecov Report
@@ Coverage Diff @@
## master #53 +/- ##
=========================================
+ Coverage 97.1% 97.21% +0.1%
=========================================
Files 18 20 +2
Lines 346 431 +85
Branches 58 68 +10
=========================================
+ Hits 336 419 +83
- Misses 10 12 +2
Continue to review full report at Codecov.
|
@kptdobe please have a look. If we merge this, we can remove |
ok, I'll review this afternoon. |
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.
in VDOMTRansformer:
- do you really want to export all static methods?
- it would be good to add js doc to all methods and declare the ones considered private with
@private
.
}); | ||
} | ||
|
||
static toHTAST(htmlstr, cb, node) { |
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.
jsdoc?
return cb(node, 'div', {}, htast.children); | ||
} | ||
|
||
static handle(cb, node, parent, 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.
jsdoc?
return result; | ||
} | ||
|
||
static default(node) { |
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.
jsdoc?
return handlers[node.type]; | ||
} | ||
|
||
match(matcher, processor) { |
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.
jsdoc?
this._matchers.push([matchfn, processor]); | ||
} | ||
|
||
matches(node) { |
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.
jsdoc?
return processors[0]; | ||
} | ||
|
||
static matchfn(ast, pattern) { |
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.
jsdoc?
}; | ||
} | ||
|
||
process() { |
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.
jsdoc?
return tohyper(h, tohast(this._root, { handlers: this._handlers })); | ||
} | ||
|
||
getDocument() { |
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.
jsdoc?
I tried the code with the initial project ( |
It is the "JSONification" of the document object which does not work. A breakpoint in the |
- addressing @kptadobe's comment: #53 (comment)
I started to look into this PR and I really do not understand where we go with this:
This looks sooo complicated for the needs we have at the moment. If you could illustrate how this would be used, that would be great. |
The basic motivation for this is outlined in @simonwex's issue adobe/project-helix#305:
So the idea is to give Mark an API for manipulating HTML that he is familiar with, instead of forcing him to learn HTAST (as great as it might be with all the unist-utils) or any new content structure (that we haven't defined in more than a couple of months, see #24)
It might be useless, but I'd argue there is little harm done and it can increase compatibility when the developer is introducing their favorite library that happens to access
Below are a couple of examples of how I could see this play out. They all have in common that the developer does not want to touch anything that looks like Markdown, but is very familiar with the DOM. Super SimpleMark is fine with the HTML content and just wants it printed as is: <body>
${content.document.innerHTML}
</body> Easy. Wrapping top-level elementsThis replaces the <div data-sly-list="${content.document.childNodes}">${item.innerHTML}</div> Adjusting HeadlinesThis takes a little work in // remove the first heading
const firstheading = content.document.querySelector('h1');
firstheading.parentNode.removeChild(firstheading);
// downgrade all remaining h1 to h2
content.document.getElementsByTagName('h1').map(heading => {
heading.outerHTML = '<h2>' + heading.innerHTML + '</h2>';
}); <body>
<h1 class="myheading">${content.meta.title}</h1>
${content.document.innerHTML}
</body> In all examples, you could even prototype the code on the client, in the web developer console before moving it server-side. |
This is much tidier than I thought it would be. You nailed the use-case. Nice work! I'll try to use it for real at some point this week, but from my static inspection, it looks like a great candidate to merge. |
Some more documentation to describe how custom sizes for responsive images can be created. |
For #43