Spaces:
Sleeping
Sleeping
File size: 1,390 Bytes
13555f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {InlineStrategy} from '../pluginStrategy'
import findRangesWithRegex from '../utils/findRangesWithRegex'
const createQuoteStyleStrategy = (): InlineStrategy => {
const quoteRegex = /^> (.*)/g
const quoteDelimiterRegex = /^> /g
return {
style: 'QUOTE',
delimiterStyle: 'QUOTE-DELIMITER',
findStyleRanges: (block) => {
const text = block.getText()
const quoteRanges = findRangesWithRegex(text, quoteRegex)
return quoteRanges
},
findDelimiterRanges: (block, styleRanges) => {
const text = block.getText()
let quoteDelimiterRanges: number[][] = []
styleRanges.forEach((styleRange) => {
const delimiterRange = findRangesWithRegex(
text.substring(styleRange[0], styleRange[1] + 1),
quoteDelimiterRegex,
).map((indices) => indices.map((x) => x + styleRange[0]))
quoteDelimiterRanges = quoteDelimiterRanges.concat(delimiterRange)
})
return quoteDelimiterRanges
},
styles: {
opacity: 0.75,
},
delimiterStyles: {
opacity: 0.4,
},
}
}
export default createQuoteStyleStrategy
|