CSDN写作Markdown编辑器中的Python命令帮手

Posted 卓晴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSDN写作Markdown编辑器中的Python命令帮手相关的知识,希望对你有一定的参考价值。

简 介: 利用Python短程序帮助对CSDN上的Markdown编辑器提供格式化的命令,可以大大提高Markdown编辑器的编写效率。本文给出了CDF的小程序。

关键词 markdowncsdn编辑快捷键定义

 

§01 CSDN写作帮手


尽管CSDNMarkdown编辑器使得网页文档编辑呈现了非常快捷的方式,大大方便了一般人员编写CSDN上的Markdown编辑,但随着使用的身世,它仍然在某些方面呈现不方便。

下面的CDF.PYPython的小程序,被驻留在计算机内存,使用LEFT_SHIFT+LEFT_CONTROL+RIGHT_CONTROL进行激活,随时提供编辑格式的帮助。对于喜欢快捷键的编程人员是在是太方便了。

1、CDF 程序

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CDF.PY                       -- by Dr. ZhuoQing 2020-05-05
#
# Note:
#============================================================

from head import *

csdn_title = '写文章-CSDN博客'

#------------------------------------------------------------
clipboardstr = clipboard.paste()

#------------------------------------------------------------
face = ''
color = ''
sizestr = ''
boldflag = 0
centerflag = 0
nbspflag = 0
endnbspflag = 0
sharpnum = 0
retflag = 0
lineflag = 0
headlineflag = 0
noteflag = 0
markflag = 0
deleteflag = 0
underlineflag = 0
headmarkflag = ''
endmarkflag = ''
codeflag = 0
blockflag = 0
greatflag = 0
circlenum = 0
italicflag = 0
notestr = ''
anchorstr = ''
urlflag = 0
fontflag = 0
rightflag = 0
headboldflag = 0
headlargeflag = 0
questionmark = 0
headnumlineflag = 1
rnflag = 0
onelineflag = 0
redarrowflag = 0
supsubflag = 0
menuflag = 0
endmarkflag = 0
thickblankflag = 0
headcolorflag = ''
headcolorflagcount = 1
brflag = 0

#------------------------------------------------------------
def str2headnumline(str, colorstr=''):
    i = 0

    if len(str) == 0: return str

    for i in range(len(str)):
        if str[0:i+1].isdigit() == False:
            if i == 0: return str
            break

    if str[i] in ". 、) )":
        return str

    if redarrowflag == 0:
#        if len(colorstr) == 0:
#            return '<font color=red>\\u27a4</font><u>' + str[0:i] + '</u> ' + str[i:]
#        else: return '<font color=%s>'%colorstr + '\\u27a4' + '</font><u>' + str[0:i] + '</u> ' + str[i:]

        if len(colorstr) == 0:
            return '<u>' + str[0:i] + '</u> ' + str[i:]
        else: return '<font color=%s>'%colorstr + '<u>' + str[0:i] + '</u></font> ' + str[i:]
    else:
        if len(colorstr) == 0:
            return '<u>' + str[0:i] + '</u> ' + str[i:]
        else: return '<font color=%s>'%colorstr + '<u>' + str[0:i] + '</u></font> ' + str[i:]

#------------------------------------------------------------
def headstrchange(allstr):
    if len(allstr) == 0: return allstr

    headmarkflag = ''
    if allstr[0] == 'o':
        if allstr[1] == 'o':
            headmarkflag = '○ '
            allstr = allstr[2:]
        else:
            headmarkflag = '● '
            allstr = allstr[1:]

    if allstr[0] == '.':
        if allstr[1] == '.':
            headmarkflag = '□ '
            allstr = allstr[2:]
        else:
            headmarkflag = '■ '
            allstr = allstr[1:]

    if allstr[0] == '+':
        if allstr[1] == '+':
            headmarkflag = '☆ '
            allstr = allstr[2:]
        else:
            headmarkflag = '★ '
            allstr = allstr[1:]

    if allstr[0] == '-':
        if allstr[1] == '-':
            headmarkflag = '△ '
            allstr = allstr[2:]
        else:
            headmarkflag = '▲ '
            allstr = allstr[1:]

    if allstr[0] == ';':
        if allstr[1] == ';':
            headmarkflag = '◇ '
            allstr = allstr[2:]
        else:
            headmarkflag = '◆ '
            allstr = allstr[1:]

    if allstr[0] == '_':
        headmarkflag = '→ '
        allstr = allstr[1:]

    if allstr[0] == ':':
        if allstr[1] == ':':
            headmarkflag = '▓ '
            allstr = allstr[2:]
        else:
            headmarkflag = '※ '
            allstr = allstr[1:]

    if allstr[0] == '%':
        headmarkflag = '# '
        allstr = allstr[1:]

    if allstr[0] == '$':
        headmarkflag = '§ '
        allstr = allstr[1:]

    if allstr[0] == '@':
        headmarkflag = '◎ '
        allstr = allstr[1:]

    if allstr[0] == '?':
        headmarkflag = '√ '
        allstr = allstr[1:]
    if allstr[0] == '?':
        headmarkflag = '√ '
        allstr = allstr[1:]

    if len(headmarkflag) > 0:
        allstr = headmarkflag + allstr
        return allstr

    #--------------------------------------------------------
    circlestr = ''
    if allstr[0] == '/':
        circlenum = allstr.count('/')
        allstr = allstr[circlenum:]
        orderstr = '①②③④⑤⑥⑦⑧⑨⑩⑾⑿⒀⒁⒂⒃⒄⒅'
        if circlenum > 18: circlenum = 18
        circlestr = orderstr[circlenum-1:circlenum] + ' '

    if allstr[0] == '|':
        circlenum = allstr.count('|')
        allstr = allstr[circlenum:]
        orderstr = 'ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ'
        if circlenum > 12: circlenum = 12
        circlestr = orderstr[circlenum-1:circlenum] + '.'

    if allstr[0] == '\\\\':
        circlenum = allstr.count('\\\\')
        allstr = allstr[circlenum:]
        orderstr = 'ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹ'
        if circlenum > 10: circlenum = 10
        circlestr = orderstr[circlenum-1:circlenum] + '.'

    if len(circlestr) > 0:
        return circlestr + allstr

    if allstr[0] >= '0' and allstr[0] <= '9':
        if len(allstr) >= 2:
            if allstr[1] == '|':
                if allstr[2] == ':':
                    allstr = '(%s)'%allstr[0] + allstr[3:]
                elif allstr[2] == '|':
                    allstr = '(%s)'%allstr[0] + allstr[3:]
                elif allstr[2:3] == ':':
                    allstr = '(%s)'%allstr[0] + allstr[3:]
                else:
                    allstr = '(%s) '%allstr[0] + allstr[2:]
            elif allstr[1] == ':':
                allstr = '(%s)'%allstr[0] + allstr[2:]
            elif allstr[1:2] == ':':
                allstr = '(%s)'%allstr[0] + allstr[2:]
            elif allstr[1] >= '0' and allstr[1] <= '9':
                if allstr[2] == '|':
                    if allstr[3] == ':':
                        allstr = '(%s)'%allstr[0:2] + allstr[4:]
                    elif allstr[2] == '|':
                        allstr = '(%s)'%allstr[0:2] + allstr[4:]
                    elif allstr[2:3] == ':':
                        allstr = '(%s)'%allstr[0:2] + allstr[4:]
                    else:
                        allstr = '(%s) '%allstr[0:2] + allstr[3:]
                elif allstr[2] == ':':
                    allstr = '(%s)'%allstr[0:2] + allstr[3:]
                elif allstr[2:3] == ':':
                    allstr = '(%s)'%allstr[0:2] + allstr[3:]

    return allstr

#------------------------------------------------------------
if len(sys.argv) > 1:
    argv1 = sys.argv[1]

    printf(sys.argv)

    #--------------------------------------------------------
    if argv1 == 'rn':
        allstr = clipboard.paste()
        if len(allstr) == 0: exit()

        allstr = allstr.replace('\\r', '\\r\\n')
        clipboard.copy(allstr)

        printf(allstr)

        tspbeep(1200, 100)
        exit()

    #--------------------------------------------------------
    argv1 = argv1.replace('2#', '##')
    argv1 = argv1.replace('3#', '###')
    argv1 = argv1.replace('4#', '####')
    argv1 = argv1.replace('5#', '#####')
    argv1 = argv1.replace('6#', '######')
    argv1 = argv1.replace('@#', '###')
    argv1 = argv1.replace('$#', '####')
    argv1 = argv1.replace('%#', '#####')
    argv1 = argv1.replace('!#', '######')
    argv1 = argv1.replace('@#', '##')
    argv1 = argv1.replace('¥#', '####')
    argv1 = argv1.replace('!#', '######')
    argv1 = argv1.replace('<>', ',')
    argv1 = argv1.replace('《》', ',')

    if argv1.count('#') > 0:
        if argv1.find('#') > 0:
            headnumlineflag = 0

        sharpnum = argv1.count('#')
        retflag = 1
        argv1 = argv1.strip('#')

    #--------------------------------------------------------
    if argv1.find("r'") >= 0:
        argv1 = argv1.replace("r'", '')
        headcolorflag = 'red'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("b'") >= 0:
        argv1 = argv1.replace("b'", '')
        headcolorflag = 'blue'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("R'") >= 0:
        argv1 = argv1.replace("R'", '')
        headcolorflag = 'darkred'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("B'") >= 0:
        argv1 = argv1.replace("B'", '')
        headcolorflag = 'slateblue'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("t'") >= 0:
        argv1 = argv1.replace("t'", '')
        headcolorflag = 'teal'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("d'") >= 0:
        argv1 = argv1.replace("d'", '')
        headcolorflag = 'seagreen'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("v'") >= 0:
        argv1 = argv1.replace("v'", '')
        headcolorflag = 'blueviolet'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("z'") >= 0:
        argv1 = argv1.replace("z'", '')
        headcolorflag = 'purple'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')
    if argv1.find("g'") >= 0:
        argv1 = argv1.replace("g'", '')
        headcolorflag = 'darkgreen'
        headcolorflagcount += argv1.count("'")
        argv1 = argv1.replace("'", '')

    #--------------------------------------------------------
    if argv1.count('b'以上是关于CSDN写作Markdown编辑器中的Python命令帮手的主要内容,如果未能解决你的问题,请参考以下文章

CSDN(Markdown)写作模板——插图表格排版

CSDN博客园等6大技术博客平台的写作体验测评

产品周报第30期|编辑器支持自定义写作模板;MarkDown编辑器接入质量分检测功能;CSDN APP V5.2.0版本发布

产品周报第30期|编辑器支持自定义写作模板;MarkDown编辑器接入质量分检测功能;CSDN APP V5.2.0版本发布

Markdown的使用方法(来自CSDN)

利用Python模拟鼠标操作,一键将GIF文件载入CSDN的Markdown编辑器