<commit_before>import React from 'react'
import markdown from './markdown'
import isReactComponent from './is-react-component'

function applyMarkdown(spec) {
    if (spec == null) {
        return string => string
    }

    let marks = Object.keys(spec)
    return string => {
        if (string == null) {
            return null
        }
        return markdown(string, marks)
            .map((item, index) => {
                if (item.mark === null) {
                    return item.text
                }

                let value = spec[item.mark]
                if (typeof value === 'string') {
                    return React.createElement(
                        'span', {
                            key: index,
                            className: value
                        },  item.text
                    )
                }
                if (isReactComponent(value)) {
                    return React.createElement(
                        value, {
                            key: index
                        },  item.text
                    )
                }
                if (React.isValidElement(value)) {
                    return React.cloneElement(
                        value, {
                            key: index
                        },  item.text
                    )
                }
                return false
            })
            .filter(a => a !== false)
    }
}

function useStyle(style, spec) {

}

export default applyMarkdown
export { useStyle }<commit_msg>add useStyle that transforms style into spec<commit_after>import React from 'react'
import markdown from './markdown'
import isReactComponent from './is-react-component'

function applyMarkdown(spec) {
    if (spec == null) {
        return string => string
    }

    let marks = Object.keys(spec)
    return (string) => {
        if (string == null) {
            return null
        }
        return markdown(string, marks)
            .map((item, index) => {
                if (item.mark === null) {
                    return item.text
                }

                let value = spec[item.mark]
                if (typeof value === 'string') {
                    return React.createElement(
                        'span', {
                            key: index,
                            className: value
                        },  item.text
                    )
                }
                if (isReactComponent(value)) {
                    return React.createElement(
                        value, {
                            key: index
                        },  item.text
                    )
                }
                if (React.isValidElement(value)) {
                    return React.cloneElement(
                        value, {
                            key: index
                        },  item.text
                    )
                }
                return false
            })
            .filter(a => a !== false)
    }
}

function useStyle(style, spec) {
    if (spec == null) {
        return null
    }
    if (style == null) {
        return spec
    }
    let result = {}
    Object.keys(spec).forEach(prop => {
        let styleProp = style[spec[prop]]
        if (styleProp !== undefined) {
            result[prop] = styleProp
        }
    })
    return result
}

export default applyMarkdown
export { useStyle }
{'fraction_non_alphanumeric': 0.09133489461358314, 'fraction_numerical': 0.0, 'mean_word_length': 0.9536878216123499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2212828', 'n_tokens_mistral': 822, 'n_tokens_neox': 776, 'n_words': 197}