Skip to content

Commit

Permalink
fix(HTML): Do not indent <address> elements
Browse files Browse the repository at this point in the history
Closes #764
  • Loading branch information
nokome committed Nov 23, 2020
1 parent baace43 commit 7880a81
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 20 deletions.
37 changes: 37 additions & 0 deletions src/__tests__/issues/764-html-indentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import schema from '@stencila/schema'
import { JSDOM } from 'jsdom'

import { HTMLCodec } from '../../codecs/html'

/**
* See https://github.com/stencila/encoda/issues/764
*
* Note the desired lack of whitespace in "FacilityGeorgiaUnited States"
*/
test('issue 764: indentation of certain HTML elements', async () => {
const html = await new HTMLCodec().dump(
schema.article({
authors: [
schema.person({
familyNames: ['Lewis'],
givenNames: ['L', 'Michelle'],
affiliations: [
schema.organization({
name:
'University of Georgia, Bioexpression and Fermentation Facility',
address: schema.postalAddress({
addressLocality: 'Georgia',
addressCountry: 'United States',
}),
}),
],
}),
],
})
)

const dom = new JSDOM(html).window.document.documentElement
expect(dom.querySelector('#author-organization-1')).toHaveTextContent(
'University of Georgia, Bioexpression and Fermentation FacilityGeorgiaUnited States'
)
})
18 changes: 8 additions & 10 deletions src/codecs/html/__file_snapshots__/elife-30274.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,16 @@ <h1 itemprop="headline">Replication Study: Transcriptional amplification in tumo
<ol data-itemprop="affiliations">
<li itemscope="" itemtype="http://schema.org/Organization" itemid="#author-organization-1"
id="author-organization-1"><span itemprop="name">University of Georgia, Bioexpression
and Fermentation Facility</span>
<address itemscope="" itemtype="http://schema.org/PostalAddress" itemprop="address">
<span itemprop="addressLocality">Georgia</span><span itemprop="addressCountry">United
States</span></address>
</li>
and Fermentation Facility</span><address itemscope=""
itemtype="http://schema.org/PostalAddress" itemprop="address"><span
itemprop="addressLocality">Georgia</span><span itemprop="addressCountry">United
States</span></address></li>
<li itemscope="" itemtype="http://schema.org/Organization" itemid="#author-organization-2"
id="author-organization-2"><span itemprop="name">Johns Hopkins University, Deep
Sequencing and Microarray Core Facility</span>
<address itemscope="" itemtype="http://schema.org/PostalAddress" itemprop="address">
<span itemprop="addressLocality">Maryland</span><span itemprop="addressCountry">United
States</span></address>
</li>
Sequencing and Microarray Core Facility</span><address itemscope=""
itemtype="http://schema.org/PostalAddress" itemprop="address"><span
itemprop="addressLocality">Maryland</span><span itemprop="addressCountry">United
States</span></address></li>
</ol><span itemscope="" itemtype="http://schema.org/Organization" itemprop="publisher">
<meta itemprop="name" content="Unknown"><span itemscope=""
itemtype="http://schema.org/ImageObject" itemprop="logo">
Expand Down
17 changes: 7 additions & 10 deletions src/codecs/html/__file_snapshots__/elife-50356.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ <h1 itemprop="headline">Disease-modifying effects of natural Δ9-tetrahydrocanna
id="author-organization-1"><span itemprop="name">Laboratory of Neuropharmacology,
Department of Experimental and Health Sciences</span><span itemscope=""
itemtype="http://schema.org/Organization" itemprop="parentOrganization"><span
itemprop="name">Universitat Pompeu Fabra</span></span>
<address itemscope="" itemtype="http://schema.org/PostalAddress" itemprop="address">
<span itemprop="addressLocality">Barcelona</span><span
itemprop="addressCountry">Spain</span></address>
</li>
itemprop="name">Universitat Pompeu Fabra</span></span><address itemscope=""
itemtype="http://schema.org/PostalAddress" itemprop="address"><span
itemprop="addressLocality">Barcelona</span><span
itemprop="addressCountry">Spain</span></address></li>
<li itemscope="" itemtype="http://schema.org/Organization" itemid="#author-organization-2"
id="author-organization-2"><span itemprop="name">IMIM (Hospital del Mar Medical Research
Institute)</span>
<address itemscope="" itemtype="http://schema.org/PostalAddress" itemprop="address">
<span itemprop="addressLocality">Barcelona</span><span
itemprop="addressCountry">Spain</span></address>
</li>
Institute)</span><address itemscope="" itemtype="http://schema.org/PostalAddress"
itemprop="address"><span itemprop="addressLocality">Barcelona</span><span
itemprop="addressCountry">Spain</span></address></li>
</ol><span itemscope="" itemtype="http://schema.org/Organization" itemprop="publisher">
<meta itemprop="name" content="Unknown"><span itemscope=""
itemtype="http://schema.org/ImageObject" itemprop="logo">
Expand Down
63 changes: 63 additions & 0 deletions src/codecs/html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,69 @@ export const beautify = (html: string): string =>
indent_inner_html: true, // Indent <head> and <body> sections
wrap_line_length: 100,
preserve_newlines: false, // Preserve existing line-breaks
// "List of tags (defaults to inline) that should not be reformatted"
inline: [
// List from list is from https://github.com/beautify-web/js-beautify/blob/97caa308491e1379b226c514f677fa4f278e15d4/js/src/html/options.js#L53
'a',
'abbr',
'acronym',
'area',
'audio',
'b',
'bdi',
'bdo',
'big',
'br',
'button',
'canvas',
'cite',
'code',
'data',
'datalist',
'del',
'dfn',
'em',
'embed',
'i',
'iframe',
'img',
'input',
'ins',
'kbd',
'keygen',
'label',
'map',
'mark',
'math',
'meter',
'noscript',
'object',
'output',
'progress',
'q',
'ruby',
's',
'samp',
'select',
'small',
'span',
'strike',
'strong',
'sub',
'sup',
'svg',
'template',
'text',
'textarea',
'time',
'tt',
'u',
'var',
'video',
'wbr',
// Additions
'address', // See https://github.com/stencila/encoda/issues/764
],
})
/* eslint-enable camelcase */

Expand Down

0 comments on commit 7880a81

Please sign in to comment.