Skip to content

Instantly share code, notes, and snippets.

@raine
Created July 23, 2020 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raine/a7215c14089fde9e47b49504eb23e636 to your computer and use it in GitHub Desktop.
Save raine/a7215c14089fde9e47b49504eb23e636 to your computer and use it in GitHub Desktop.
Quick and dirty way to log html tag in browser console.log with bold style
function consoleLogWithBoldTags(str: string) {
const openTag = /(<[a-z]+?>)/g
const closeTag = /(<\/[a-z]+?>)/g
const parts = str
.replace(openTag, '|||$1')
.replace(closeTag, '$1|||')
.split('|||')
.filter((p) => p !== ' ')
console.log(
parts
.map((p) => {
return '%c' + p.trim()
})
.join(' '),
...parts.map((p) => {
return p.match(openTag) ? 'font-weight: bold;' : 'font-weight: normal'
})
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment