olDelimiterStyleStrategy.ts
TLDR
This file defines a strategy for applying a specific style to ordered list delimiters in a Markdown plugin.
Methods
createOLDelimiterStyleStrategy
This method creates an inline strategy object that can be used to apply a specific style to ordered list delimiters. The strategy object returned by this method contains the following properties:
-
style
: The style name, which is set to 'OL-DELIMITER'. -
findStyleRanges
: A function that takes a block of text and returns an array of ranges where the ordered list delimiter style should be applied. This function uses a regular expression to find ranges that match the pattern for ordered list delimiters (e.g., "1. ", "2. ", etc.). -
styles
: An object that defines the styles that should be applied to the ordered list delimiters. In this case, the only style being applied isfontWeight: 'bold'
.
Classes
None
// 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 createOLDelimiterStyleStrategy = (): InlineStrategy => {
const olDelimiterRegex = /^\d{1,3}\. /g
return {
style: 'OL-DELIMITER',
findStyleRanges: (block) => {
const text = block.getText()
const olDelimiterRanges = findRangesWithRegex(text, olDelimiterRegex)
return olDelimiterRanges
},
styles: {
fontWeight: 'bold',
},
}
}
export default createOLDelimiterStyleStrategy