File size: 837 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
// 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 createInlineCodeStyleStrategy = (): InlineStrategy => {
    const codeRegex = /(`)([^\n\r`]+?)(`)/g

    return {
        style: 'INLINE-CODE',
        findStyleRanges: (block) => {
            // Don't allow inline code inside of code blocks
            if (block.getType() === 'code-block') {
                return []
            }

            const text = block.getText()
            const codeRanges = findRangesWithRegex(text, codeRegex)
            return codeRanges
        },
        styles: {
            fontFamily: 'monospace',
        },
    }
}

export default createInlineCodeStyleStrategy