终端标记查看器

mdv的Python项目详细描述


终端降价查看器

生成状态coverage statuspypi versioncode style:black

远程编辑多个MD文件时,例如 mkdocs项目,在编辑之间切换上下文 终端和查看浏览器可能会对效率产生一些影响。 有时也没有浏览器,比如通过安全网关 只是一组固定的应用程序。 此外,阅读的效率和便利性也经常得到显著的提高 使用颜色。 最后,对cli应用程序使用这样的东西可能会改进用户输出, 例如,获取帮助文本。

这就是mdv,一个基于python的终端标记查看器 一个不错的选择。

如果标记通常"简单"到可以在256色终端(除了图像)上读取的程度。

您还可以将mdv用作源代码的查看器,最好是在代码中有带标记的docstring:

 src=

<

~/terminal_markdown_viewer$catsetup.py#!/usr/bin/env python2.7# coding: utf-8"""_# Mdv installation## Usage    [sudo] ./setup.py install----"""fromsetuptoolsimportsetup,find_packagesimportmdvsetup(name='mdv',version=mdv.__version__,

(docstring后面的''''u'告诉mdv下面的标记)


< Buff行情>

mdv是一个概念验证黑客:虽然对于简单的结构,它的工作做得很好,但对于复杂的降价,你想使用其他工具。 尤其是对于内联的html,它只是失败了。


功能

  • 大量的主题组合:mdv附带了>;200亮度排序的主题,从html主题转换而来符合ANSI标准。这些可以组合用于代码与常规降价输出…
  • 警告
  • 桌子,包括避免"交错"的宽桌子处理
  • 有点容易破解,全部都在一个模块中
  • 也可用作lib
  • 文件更改监视器
  • 文本换行
  • 源代码高亮
  • 小目录更改监视器(在处理多个文件时方便使用cames,以便始终显示当前文件)
    • 它可以对文件更改运行任意命令
    • 它将文件路径、原始内容和预分类内容传递给另一个命令 注:穷人的实现,投票。如果你想要更好的东西,可以选择基于inotify的工具。

备选方案

我所认识的人(也正是他们让我写了mdv;-):

  1. JS社区中有相当多的人(例如msee、ansidown、ansimd和nd,这都很好),但他们需要nodejs&npm,而我的服务器上没有nodejs&npm。同时,我个人希望在整个过程和prob中都支持表处理和警告。太老了,无法破解别人的js(与自己的js抗争已久)。但是看看他们,在这个早期版本中,他们做了一些比mdv更好的事情(我试着向他们学习)。另外,这个值得一看;-)
  2. pandoc->;html->;elinks、lynx或pandoc->;groff->;man。(很重,很难在其他程序中使用。造型次优)
  3. vimcat(也很重,很难在其他程序中内联使用)
  4. < > >

    小结:由于MDV的早期状态,对于准备生产的健壮降价查看(例如,对于您的客户),我仍然建议使用ND。对于玩游戏,特别是主题化或使用python时,这个可能是一个有效的替代方法。

    安装

    pip install mdv
    

    如果您得到无属性html_占位符:更新您的降价包。

    这里是一个macport(谢谢alja_)。

    手动安装:要求

    另外还有一个256色的终端(目前最好是深色背景)和一些特殊分隔字符的字体支持(您可以通过配置进行更改)。

    < Buff行情>

    对于光的术语,您只需要还原主题的5种颜色,因为它们是按亮度排序的。

    我没有在windows上测试任何东西。

    手动安装:设置

    通过设置工具分发。如果未安装setuptools,请运行:

    pip install setuptools
    

    使用内部提供的setup.py,即run:

    sudo ./setup.py install
    (or ./setup.py install --user to install only for the current user)
    

    用法

    CLI

    # Usage:
    
        mdv [OPTIONS] MDFILE
    
    # Options:
    
        MDFILE    : Path to markdown file
        -A        : Strip all ansi (no colors then)
        -C MODE   : Sourcecode highlighting mode
        -H        : Print html version
        -L        : Backwards compatible shortcut for '-u i'
        -M DIR    : Monitor directory for markdown file changes
        -T C_THEME: Theme for code highlight. If not set: Using THEME.
        -X Lexer  : Default lexer name (default: python). Set -x to use it always.
        -b TABL   : Set tab_length to sth. different than 4 [default: 4]
        -c COLS   : Fix columns to this (default: your terminal width)
        -f FROM   : Display FROM given substring of the file.
        -h        : Show help
        -i        : Show theme infos with output
        -l        : Light background (not yet supported)
        -m        : Monitor file for changes and redisplay FROM given substring
        -n NRS    : Header numbering (default: off. Say e.g. -3 or 1- or 1-5
        -t THEME  : Key within the color ansi_table.json. 'random' accepted.
        -u STYL   : Link Style (it=inline table=default, h=hide, i=inline)
        -x        : Do not try guess code lexer (guessing is a bit slow)
    
    
    # Notes:
    
    We use stty tool to derive terminal size. If you pipe into mdv we use 80 cols.
    
    ## To use mdv.py as lib:
    
    Call the main function with markdown string at hand to get a
    formatted one back. Sorry then for no Py3 support, accepting PRs if they don't screw Py2.
    
    ## FROM:
    
    FROM may contain max lines to display, seperated by colon.
    Example:
    
        -f 'Some Head:10' -> displays 10 lines after 'Some Head'
    
    If the substring is not found we set it to the *first* character of the file -
    resulting in output from the top (if your terminal height can be derived correctly through the stty cmd).
    
    ## Code Highlighting
    
    Set -C <all|code|doc|mod> for source code highlighting of source code files.
    Mark inline markdown with a '_' following the docstring beginnings.
    
    - all: Show markdown docstrings AND code (default if you say, e.g. `-C.`)
    - code: Only Code
    - doc: Only docstrings with markdown
    - mod: Only the module level docstring
    
    
    ## File Monitor:
    
    If FROM is not found we display the whole file.
    
    ## Directory Monitor:
    
    We check only text file changes, monitoring their size.
    
    By default .md, .mdown, .markdown files are checked but you can change like `-M 'mydir:py,c,md,'` where the last empty substrings makes mdv also monitor any file w/o extension (like 'README').
    
    ### Running actions on changes:
    
    If you append to `-M` a `'::<cmd>'` we run the command on any change detected (sync, in foreground).
    
    The command can contain placeholders:
    
        _fp_     # Will be replaced with filepath
        _raw_    # Will be replaced with the base64 encoded raw content
                   of the file
        _pretty_ # Will be replaced with the base64 encoded prettyfied output
    
    Like: mdv -M './mydocs:py,md::open "_fp_"'  which calls the open
    command with argument the path to the changed file.
    
    
    ## Themes
    
    ### Theme Rollers
    
    
        mdv -T all [file]:  All available code styles on the given file.
        mdv -t all [file]:  All available md   styles on the given file.
                            If file is not given we use a short sample file.
    
    So to see all code hilite variations with a given theme:
    
    Say C_THEME = all and fix THEME
    
    Setting both to all will probably spin your beach ball...
    
    ### Environ Vars
    
    `$MDV_THEME` and `$MDV_CODE_THEME` are understood, e.g. `export
    MDV_THEME=729.8953` in your .bashrc will give you a consistent color scheme.
    
    < Buff行情>

    关于奇怪的主题id:这些数字是计算出的5种主题颜色的总亮度。

    内联

    mdv的设计是为了在其他(py2)程序有md时能够很好地使用,md应该显示给用户:

    importmdv# config like this:mdv.term_columns=60# calling like this (all CLI options supported, check def mainformatted=mdv.main(my_raw_markdown,c_theme=...)
    < Buff行情>

    注意,我在\u main\u中将defaultencoding设置为utf-8。我将此设置作为我的默认python2设置,并且没有测试不带O的内联用法。请检查此设置是否存在风险。

    内联用例示例:单击模块docu

    Armin Ronacher的 单击是编写更大的cli应用程序的一个很好的框架,但是它的帮助文本有点乏味,需要定制。

    方法如下:

    编写一个带有函数但不带文档字符串,如图所示:

    @pass_contextdefcli(ctx,action,name,host,port,user,msg):""" docu from module __doc__ """

    在模块级别,您可以为其提供降价,例如:

    ~/axc/plugins/zodb_sub $ cat zodb.py | head
    """# Fetch and push ZODB trees## ACTION: < info | pull | push | merge | dump | serve>- info:  Requests server availability information(...)

    您在点击模块导入时设置的时间:

    ### Source
    # Header 1
    ## Header 2
    ### Header 3
    #### Header 4
    ##### Header 5
    ###### Header 6
    ```python
    """ Test """
    # Make Py2 >>> Py3:
    import os, sys; reload(sys); sys.setdefaultencoding('utf-8')
    # no? see http://stackoverflow.com/a/29832646/4583360 ...
    
    # code analysis for hilite:
    try:
        from pygments import lex, token
        from pygments.lexers import get_lexer_by_name, guess_lexer
    ```
    
    | Tables | Fmt |
    | -- | -- |
    | !!! hint: wrapped | 0.1 **strong** |
    
    !!! note: title
        this is a Note
    
    0

    最后在应用程序模块中执行此操作:

    ### Source
    # Header 1
    ## Header 2
    ### Header 3
    #### Header 4
    ##### Header 5
    ###### Header 6
    ```python
    """ Test """
    # Make Py2 >>> Py3:
    import os, sys; reload(sys); sys.setdefaultencoding('utf-8')
    # no? see http://stackoverflow.com/a/29832646/4583360 ...
    
    # code analysis for hilite:
    try:
        from pygments import lex, token
        from pygments.lexers import get_lexer_by_name, guess_lexer
    ```
    
    | Tables | Fmt |
    | -- | -- |
    | !!! hint: wrapped | 0.1 **strong** |
    
    !!! note: title
        this is a Note
    
    1

    输出有以下颜色:

     src=

    以较小的术语来说,可以很好地重写:

     src=

    此外,在模块\uu doc中进行标记使添加到像mkdocs这样的全局项目docu框架中变得简单。

    定制

    您可以以yaml格式提供$home/.mdv中的所有cli参数。

    您可以通过$home/.mdv.py获得更多的灵活性,如果存在,当 运行main

    或者,在mdv.py中,您可以直接更改一些配置。

    ### Source
    # Header 1
    ## Header 2
    ### Header 3
    #### Header 4
    ##### Header 5
    ###### Header 6
    ```python
    """ Test """
    # Make Py2 >>> Py3:
    import os, sys; reload(sys); sys.setdefaultencoding('utf-8')
    # no? see http://stackoverflow.com/a/29832646/4583360 ...
    
    # code analysis for hilite:
    try:
        from pygments import lex, token
        from pygments.lexers import get_lexer_by_name, guess_lexer
    ```
    
    | Tables | Fmt |
    | -- | -- |
    | !!! hint: wrapped | 0.1 **strong** |
    
    !!! note: title
        this is a Note
    
    2

    任何导入模块都可以覆盖这些模块全局变量。

    如果您还需要其他主题,请将它们添加到ansi_tables.json文件中,方法是在其中添加您的ansi代码。

    屏幕截图

    随机结果,使用主题滚轮功能:

    second

    请注意,当表格不适合(最后一张图片)时,表格块会被拆分。

    待办事项

    性能测试

    呈现此自述文件100次:

    ### Source
    # Header 1
    ## Header 2
    ### Header 3
    #### Header 4
    ##### Header 5
    ###### Header 6
    ```python
    """ Test """
    # Make Py2 >>> Py3:
    import os, sys; reload(sys); sys.setdefaultencoding('utf-8')
    # no? see http://stackoverflow.com/a/29832646/4583360 ...
    
    # code analysis for hilite:
    try:
        from pygments import lex, token
        from pygments.lexers import get_lexer_by_name, guess_lexer
    ```
    
    | Tables | Fmt |
    | -- | -- |
    | !!! hint: wrapped | 0.1 **strong** |
    
    !!! note: title
        this is a Note
    
    3
    • markdown比commonmark w/o扩展更好,但是表和隔离代码除外 对于99%的用户来说是绝对必需的。

    • paka是c引用库的包装器->;需要编译。

    • 槲寄生是纯粹的蟒蛇,疯狂到它们比普通马克快得多。 他们用pypy语言说他们的速度甚至更快。

    槲寄生的缺点:py2只能通过叉子。

    学分

    pygments(使用它们的lexer)

    制表

    当然,python标记项目

    更新:下一版本将基于Commonmark…

    更新

    2016年7月:

    有点像是长时间没有更新的借口: 我确实开始在commonmark的基础上开发一个更可靠的版本,但是 这超出了范围,变成了一个通用的html终端查看器,它将 可能永远不会完成:-/

    所以至少这里有一个更新,包含了你们作为prs发送的内容,谢谢大家!!< >

    • 通过setup.py安装和依赖项(谢谢 马丁
    • 支持echo-e"foo\n bar"mdv-和"light"主题(谢谢 斯坦尼斯拉夫
    • 还有一些关于python2.7、文件位置和pyyaml的改进,谢谢大家。

    也:

    • 修复了嵌套有序和无序列表中最明显的错误
    • 固定粗体标记
    • 不同颜色的lis突出显示T标记
    • 添加了源代码突出显示模式,该模式还突出显示标记中的docstring(-c<;mode>;
    • "测试"文件夹中的某些测试
    • 现在使用textwrap进行包装,以避免出现一些被投诉的单词中断
    • 现在可以提供默认的lexer,例如-x javascript[-x]
    • 已修复但未呈现强文本
    • pip安装mdv

    2016年11月:

    • 特拉维斯

    • 内联链接表

     src=

    2018年9月:

    • 合并了一些prs。
    • 像样的代码格式化程序。不过,这周末的黑客攻击并没有变得更具可读性。嗯,也许有一点。
    • 修改后的py3支持(终于找到了它的和平,因为它们在任何地方都强制使用utf-8,新功能开始超过无需解码所有内容的噩梦)。
    • py3中的缩进代码被破坏,修复了这个问题。为什么,PY3,你是在制造像"B'foo"这样的垃圾,而不是提高或自动解码?
    • 增加了标题编号功能(-n 2-4-n 1-

    欢迎加入QQ群-->: 979659372 Python中文网_新手群

    推荐PyPI第三方库


热门话题
java创建猜谜游戏程序   JavaWebSocketContainer。connectToServer似乎挂起了   如何在java中中断函数   java c#socket client multiple BeginSend()未到达服务器   不可见的组件然后在Java中的窗格之间切换   java在应用程序类中使用静态接口安全吗?   java等待函数完成,直到回调到来   使用DataOutputStream时的java新行,Android   java服务对象的定义是什么?   基于视图的javahibernate复合密钥   java将varchar连接到char在JPA(oracle)中不起作用   如何在java中通过point类读取多个点?