简体   繁体   English

逆向工程字符串格式化过程

[英]Reverse engineer string formarting process

I am using slate-react editor for my wysiwyg data entry component that will be displayed on Telegram.我正在为我的所见即所得数据输入组件使用 slate-react 编辑器,该组件将显示在 Telegram 上。

Text input is then formatted as per Telegram's requirement as this example shows:然后按照 Telegram 的要求对文本输入进行格式化,如本例所示:

Slate Object
[
    {
        "type": "paragraph",
        "children": [
            {
                "text": "Dry grains to moisture content of below 12 percent and dress with crop "
            },
            {
                "text": "protection ",
                "bold": true
            },
            {
                "text": "products such as Actellic 2%. Seeds meant for planting should not be stored for more than six "
            },
            {
                "text": "months",
                "underline": true
            },
            {
                "text": ". For more "
            },
            {
                "text": "information",
                "underline": true
            },
            {
                "text": ", please contact your "
            },
            {
                "text": "local ",
                "italic": true
            },
            {
                "text": "Extension Agent."
            }
        ]
    }
]

I then format the string to Telegram specs as follows:然后我将字符串格式化为 Telegram 规范,如下所示:

Dry grains to moisture content of below 12 percent and dress with crop **protection **products such as Actellic 2%. Seeds meant for planting should not be stored for more than six months. For more information, please contact your _local _Extension Agent.

I would now like to reverse engineer the process so that I can generate the object above if given such a string so that I'm able to display it on the editor.我现在想对该过程进行逆向工程,以便如果给定这样的字符串,我可以生成上面的 object,以便我能够在编辑器上显示它。 I would like help in formulating the function that would achieve the intended result.我想帮助制定能够达到预期结果的 function。

For those who may need such information in future, I got pointer from comments thanks to @Phil, I was able to search through the net for markdown tokenizers.对于将来可能需要此类信息的人,感谢@Phil,我从评论中获得了指针,我能够在网上搜索 markdown 标记器。 Prismjs works like a charm. Prismjs 就像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM