linux命令行预览markdown文件

释放双眼,带上耳机,听听看~!

# linux 命令行预览 markdown 文件

本文讲解如何在 linux 系统上用命令行预览本地或网络上的 markdown 文件。我们平时预览 markdown 文件可能是使用各种文本编辑器,有没有更加轻量的方法呢? 这里给大家提供一个基于 golang 的小工具 glow。

# 1. 安装 glow

官网地址:https://github.com/charmbracelet/glow
可以直接下载编译后的二进制文件。

# 2. 使用

使用glow预览自带的README文件,效果如下:

(py3.6) [email protected]:/data2/programInstaller/tmp$ ll
总用量 16036
drwxrwxr-x  2 wangshibiao wangshibiao     4096 11月  5 09:59 ./
drwxrwxr-x 33 wangshibiao wangshibiao     4096 11月  5 09:58 ../
-rwxr-xr-x  1 wangshibiao wangshibiao 16400384 10月 27 22:24 glow*
-rw-r--r--  1 wangshibiao wangshibiao     1075 10月  5 19:59 LICENSE
-rw-r--r--  1 wangshibiao wangshibiao     6108 10月 27 22:13 README.md
(py3.6) [email protected]:/data2/programInstaller/tmp$ ./glow ./README.md 

   Glow                                                                                                               
                                                                                                                      
  Render markdown on the CLI, with pizzazz!                                                                           
                                                                                                                      
                                                                                                                      
                                                                                                                      
  ## What is it?                                                                                                      
                                                                                                                      
  Glow is a terminal based markdown reader designed from the ground up to bring out the beauty—and power—of the CLI.
                                                                                                                      
  Use it to discover markdown files, read documentation directly on the command line and stash markdown files to your 
  own private collection so you can read them anywhere. Glow will find local markdown files in subdirectories or a    
  local Git repository.                                                                                               
                                                                                                                      
  By the way, all data stashed is encrypted end-to-end: only you can decrypt it. More on that below.                  
                                                                                                                      
  ## Installation                                                                                                     
                                                                                                                      
  Use your fave package manager:                                                                                      
                                                                                                                      
    # macOS or Linux                                                                                                  
    brew install glow                                                                                                 
                                                                                                                      
    # macOS (with MacPorts)                                                                                           
    sudo port install glow                                                                                            
                                                                                                                      
    # Arch Linux (btw)                                                                                                
    yay -S glow                                                                                                       
                                                                                                                      
    # Void Linux                                                                                                      
    xbps-install -S glow                                                                                              
                                                                                                                      
    # Nix                                                                                                             
    nix-env -iA nixpkgs.glow                                                                                          
                                                                                                                      
    # FreeBSD                                                                                                         
    pkg install glow                                                                                                  
                                                                                                                      
  Or download a binary from the releases https://github.com/charmbracelet/glow/releases page. MacOS, Linux, Windows,  
  FreeBSD, and OpenBSD binaries are available, as well as Debian, RPM, and Alpine packages. ARM builds are also       
  available for Linux, FreeBSD, and OpenBSD.                                                                          
                                                                                                                      
  Or just build it yourself (requires Go 1.13+):                                                                      
                                                                                                                      
    git clone https://github.com/charmbracelet/glow.git                                                               
    cd glow                                                                                                           
    go build                                                                                                          
                                                                                                                      
  ## The TUI                                                                                                          
                                                                                                                      
  Simply run  glow  without arguments to start the textual user interface and browse local and stashed markdown. Glow 
  will find local markdown files in the current directory and below or, if you’re in a Git repository, Glow will     
  search the repo.                                                                                                    
                                                                                                                      
  Markdown files can be read with Glow's high-performance pager. Most of the keystrokes you know from  less  are the  
  same, but you can press  ?  to list the hotkeys.                                                                    
                                                                                                                      
  ### Stashing                                                                                                        
                                                                                                                      
  Glow works with the Charm Cloud to allow you to store any markdown files in your own private collection. You can    
  stash a local document from the Glow TUI by pressing  s .                                                           
                                                                                                                      
  You can also stash from the CLI:                                                                                    
                                                                                                                      
    glow stash README.md                                                                                              
                                                                                                                      
  Then, when you run  glow  without arguments will you can browse through your stashed documents. This is a great way 
  to keep track of things that you need to reference often.                                                           
                                                                                                                      
  Stashing is private, its contents will not be exposed publicly, and it's encrypted end-to-end. More on encryption   
  below.                                                                                                              
                                                                                                                      
  ## The CLI                                                                                                          
                                                                                                                      
  In addition to a TUI, Glow has a CLI for working with Markdown. To format a document use a markdown source as the   
  primary argument:                                                                                                   
                                                                                                                      
    # Read from file                                                                                                  
    glow README.md                                                                                                    
                                                                                                                      
    # Read from stdin                                                                                                 
    glow -                                                                                                            
                                                                                                                      
    # Fetch README from GitHub / GitLab                                                                               
    glow github.com/charmbracelet/glow                                                                                
                                                                                                                      
    # Fetch markdown from HTTP                                                                                        
    glow https://host.tld/file.md                                                                                     
                                                                                                                      
  ### Stashing                                                                                                        
                                                                                                                      
  You can also stash documents from the CLI:                                                                          
                                                                                                                      
    glow stash README.md                                                                                              
                                                                                                                      
  Then, when you run  glow  without arguments will you can browse through your stashed documents. This is a great way 
  to keep track of things that you need to reference often.                                                           
                                                                                                                      
  ### Word Wrapping                                                                                                   
                                                                                                                      
  The  -w  flag lets you set a maximum width at which the output will be wrapped:                                     
                                                                                                                      
    glow -w 60                                                                                                        
                                                                                                                      
  ### Paging                                                                                                          
                                                                                                                      
  CLI output can be displayed in your preferred pager with the  -p  flag. This defaults to the ANSI-aware  less -r  if 
  $PAGER  is not explicitly set.                                                                                      
                                                                                                                      
  ### Styles                                                                                                          
                                                                                                                      
  You can choose a style with the  -s  flag. When no flag is provided  glow  tries to detect your terminal's current  
  background color and automatically picks either the  dark  or the  light  style for you.                            
                                                                                                                      
    glow -s [dark|light]                                                                                              
                                                                                                                      
  Alternatively you can also supply a custom JSON stylesheet:                                                         
                                                                                                                      
    glow -s mystyle.json                                                                                              
                                                                                                                      
  For additional usage details see:                                                                                   
                                                                                                                      
    glow --help                                                                                                       
                                                                                                                      
  Check out the Glamour Style Section https://github.com/charmbracelet/glamour/blob/master/styles/gallery/README.md to
  find more styles. Or make your own https://github.com/charmbracelet/glamour/tree/master/styles!                     
                                                                                                                      
  ## The Config File                                                                                                  
                                                                                                                      
  If you find yourself supplying the same flags to  glow  all the time, it's probably a good idea to create a config  
  file. Run  glow config , which will open it in your favorite $EDITOR. Alternatively you can manually put a file     
  named  glow.yml  in the default config path of you platform. If you're not sure where that is, please refer to  glow --
  help .                                                                                                              
                                                                                                                      
  Here's an example config:                                                                                           
                                                                                                                      
    # style name or JSON path (default "auto")                                                                        
    style: "light"                                                                                                    
    # show local files only; no network (TUI-mode only)                                                               
    local: true                                                                                                       
    # word-wrap at width                                                                                              
    width: 80                                                                                                         
                                                                                                                      
  ## ? Encryption: How It Works                                                                                      
                                                                                                                      
  Encryption works by issuing symmetric keys (basically a generated password) and encrypting it with the local SSH    
  public key generated by the open-source charm https://github.com/charmbracelet/charm library. That encrypted key is 
  then sent up to our server. We can’t read it since we don’t have your private key. When you want to decrypt       
  something or view your stash, that key is downloaded from our server and decrypted locally using the SSH private    
  key. When you link accounts, the symmetric key is encrypted for each new public key. This happens on your machine   
  and not our server, so we never see any unencrypted data.                                                           
                                                                                                                      
  ## License                                                                                                          
                                                                                                                      
  MIT https://github.com/charmbracelet/glow/raw/master/LICENSE                                                        
                                                                                                                      
  Part of Charm https://charm.sh.                                                                                     
                                                                                                                      
                                                                                                                      
  Charm热爱开源! / Charm loves open source!                                                                           

(py3.6) [email protected]:/data2/programInstaller/tmp$

可以看出,渲染效果有些瑕疵,有的地方并没有渲染好,如有的地方应该换行并没有换行。
期待后续可以不断完善或出现更好的工具。

文章来源于互联网:
linux命令行预览markdown文件

人已赞赏
技术杂烩杂七杂八网站建设

WordPress两种方法实现上传媒体图片文件自动重命名

2020-11-4 17:19:54

JavaScriptPHP学习笔记技术杂烩网站建设

CodeFec - 统计API

2020-11-8 18:22:18

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索