Skip to content

Commit

Permalink
fix(HTML encoding): Add support for encoding CreativeWork
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome authored and alex-ketch committed Feb 16, 2022
1 parent cacbb15 commit 0d1217d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rust/codec-html/src/encode/works.rs
Expand Up @@ -18,6 +18,7 @@ impl ToHtml for CreativeWorkTypes {
CreativeWorkTypes::AudioObject(node) => node.to_html(context),
CreativeWorkTypes::Claim(node) => node.to_html(context),
CreativeWorkTypes::Collection(node) => node.to_html(context),
CreativeWorkTypes::CreativeWork(node) => node.to_html(context),
CreativeWorkTypes::Figure(node) => node.to_html(context),
CreativeWorkTypes::ImageObject(node) => node.to_html(context),
CreativeWorkTypes::Table(node) => node.to_html(context),
Expand All @@ -36,6 +37,16 @@ impl ToHtml for CreativeWorkContent {
}
}

impl ToHtml for CreativeWork {
fn to_html(&self, context: &EncodeContext) -> String {
elem(
"article",
&[attr_itemtype::<Self>(), attr_id(&self.id)],
&self.content.to_html(context),
)
}
}

impl ToHtml for Article {
fn to_html(&self, context: &EncodeContext) -> String {
let toolbar = elem("stencila-document-toolbar", &[], "");
Expand Down Expand Up @@ -305,7 +316,6 @@ to_content_html!(MediaObject, Node::MediaObject, to_inline);
to_content_html!(VideoObject, Node::VideoObject, to_inline);

// Not yet implemented
impl ToHtml for CreativeWork {}
impl ToHtml for Periodical {}
impl ToHtml for PublicationIssue {}
impl ToHtml for PublicationVolume {}
Expand Down
35 changes: 35 additions & 0 deletions rust/codec-html/src/snapshots/encode_nodes@creative-work.json.snap
@@ -0,0 +1,35 @@
---
source: rust/codec-html/src/encode.rs
assertion_line: 425
expression: html
input_file: fixtures/nodes/creative-work.json

---
<article data-itemscope="root" itemtype="http://schema.stenci.la/CreativeWork" itemscope>
<p itemtype="http://schema.stenci.la/Paragraph" itemscope>
<span>A fixture that is a creative work containing code nodes.</span>
<span>Why? Because in some circumstances, instead of nested, structured content (e.g. an `Article`),</span>
<span>we want to use a flat array of nodes.</span>
</p>
<stencila-code-chunk itemtype="http://schema.stenci.la/CodeChunk" itemscope id="cc-1" programming-language="">
<meta itemprop="programmingLanguage" content=""/>
<pre data-itemprop="text" slot="text"># Some code</pre>
<stencila-code-dependencies slot="code-dependencies">
<div data-itemprop="codeDependencies">
</div>
</stencila-code-dependencies>
<stencila-code-dependencies slot="code-dependents">
<div data-itemprop="codeDependents">
</div>
</stencila-code-dependencies>
<div data-itemprop="outputs" slot="outputs">
<img itemtype="http://schema.org/ImageObject" itemscope src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNkYvhfz0AEYBxVSF+FAA/eDwup9bzCAAAAAElFTkw"/>
</div>
<div data-itemprop="errors" slot="errors">
</div>
<span data-itemprop="label" slot="label">
</span>
<figcaption data-itemprop="caption" slot="caption">
</figcaption>
</stencila-code-chunk>
</article>

0 comments on commit 0d1217d

Please sign in to comment.