mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add makeHighlightedMarkup helper
This commit is contained in:
parent
3b60fef8cb
commit
ef15f12198
1 changed files with 40 additions and 0 deletions
|
|
@ -4,6 +4,46 @@ import {
|
||||||
storkScriptURL
|
storkScriptURL
|
||||||
} from '~/helpers/stork/config.js'
|
} from '~/helpers/stork/config.js'
|
||||||
|
|
||||||
|
|
||||||
|
export function makeHighlightedMarkup ( options = {} ) {
|
||||||
|
const {
|
||||||
|
text,
|
||||||
|
highlight_ranges,
|
||||||
|
withElipsis = true,
|
||||||
|
} = options
|
||||||
|
|
||||||
|
if ( highlight_ranges.length === 0 ) return [ text ]
|
||||||
|
|
||||||
|
const highlighted_text = highlight_ranges.map( range => {
|
||||||
|
const {
|
||||||
|
beginning,
|
||||||
|
end
|
||||||
|
} = range
|
||||||
|
|
||||||
|
const before = text.slice( 0, beginning )
|
||||||
|
const target = text.slice( beginning, end + 1 )
|
||||||
|
const after = text.slice( end + 1 )
|
||||||
|
|
||||||
|
// console.log({
|
||||||
|
// before,
|
||||||
|
// target,
|
||||||
|
// after
|
||||||
|
// })
|
||||||
|
|
||||||
|
// `<span class="stork-highlighted-text">${ highlighted_text }</span>`
|
||||||
|
|
||||||
|
return [
|
||||||
|
withElipsis ? '...' : '',
|
||||||
|
before.trim(),
|
||||||
|
/* html */` <span class="stork-highlighted-text font-bold bg-green-800 rounded px-1">${ target.trim() }</span> `,
|
||||||
|
after.trim(),
|
||||||
|
withElipsis ? '...' : '',
|
||||||
|
].join('')
|
||||||
|
} )
|
||||||
|
|
||||||
|
return highlighted_text
|
||||||
|
}
|
||||||
|
|
||||||
export class StorkClient {
|
export class StorkClient {
|
||||||
constructor ( options = {} ) {
|
constructor ( options = {} ) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue