Skip to content

Commit

Permalink
Output HTML in code preview without formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Nov 15, 2023
1 parent 024521b commit c9f891b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ import hljs from 'highlight.js'
* @returns {string} Code with syntax highlighting
*/
export function highlight(code, language) {
return hljs.highlight(code.trim(), { language: language || 'plaintext' })
.value
return hljs.highlight(code, { language: language || 'plaintext' }).value
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render } from '@govuk-frontend/lib/components'
import beautify from 'js-beautify'

/**
* Component HTML code (formatted)
Expand All @@ -10,20 +9,7 @@ import beautify from 'js-beautify'
* @returns {string} HTML rendered by the component
*/
export function getHTMLCode(componentName, options) {
const html = render(componentName, { ...options, env: this.env })

// Default beautify options
const beautifyOptions = beautify.html.defaultOptions()

return beautify.html(html, {
indent_size: 2,
// Ensure nested labels in headings are indented properly
inline: beautifyOptions.inline.filter((tag) => !['label'].includes(tag)),
// Remove blank lines
max_preserve_newlines: 0,
// Ensure attribute wrapping in header SVG is preserved
wrap_attributes: 'preserve'
})
return render(componentName, { ...options, env: this.env })
}

/**
Expand Down

0 comments on commit c9f891b

Please sign in to comment.