Skip to content

Commit 21c3933

Browse files
authored
Merge pull request #13 from sphinx-notes/doc
Document
2 parents b7c3fa4 + 624215c commit 21c3933

File tree

6 files changed

+463
-28
lines changed

6 files changed

+463
-28
lines changed

doc/_assets/vim.cast

Lines changed: 122 additions & 0 deletions
Large diffs are not rendered by default.

doc/_assets/zsh.cast

Lines changed: 158 additions & 0 deletions
Large diffs are not rendered by default.

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
extensions = [
3636
'sphinx.ext.githubpages',
3737
'snippet.ext',
38+
'sphinxcontrib.asciinema'
3839
]
3940

4041
snippet_config = {

doc/index.rst

Lines changed: 171 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,215 @@
22
sphinxnotes-snippet
33
===================
44

5-
------------------------------------------------------
6-
Non-intrusive snippet manager for Sphinx documentation
7-
------------------------------------------------------
8-
95
.. image:: https://img.shields.io/github/stars/sphinx-notes/snippet.svg?style=social&label=Star&maxAge=2592000
106
:target: https://github.com/sphinx-notes/snippet
117

128
:version: |version|
139
:copyright: Copyright ©2021 by Shengyu Zhang.
1410
:license: BSD, see LICENSE for details.
1511

16-
.. contents::
12+
Inspecting snippets of Sphinx documentation.
13+
14+
.. _Sphinx: https://www.sphinx-doc.org/
15+
16+
.. contents:: Table of Contents
1717
:local:
1818
:backlinks: none
1919

20+
Introduction
21+
============
22+
23+
Documents in Sphinx can be parsed into doctree_ (In other words, Abstract Syntax Tree), all contents of documents are parsed into node of this tree. The :ref:`ext` collects snippets (meaningful doctree_ nodes) during the build phase of Sphinx, and provide a :ref:`cli` for your accessing.
24+
25+
.. _doctree: https://docutils.sourceforge.io/docs/ref/doctree.html
26+
27+
How It Works
28+
------------
29+
30+
In more detail, when collecting snippets, the :ref:`ext` does these things:
31+
32+
- Create unique ID
33+
- Collect meta info of snippet
34+
- Extract keywords from snippet content (In NLP way)
35+
36+
- For Chinese content, keywords are converted to PinYin
37+
38+
- Dump the aboved information to disk
39+
40+
The :ref:`cli` can read these information from disk, list snippets or get snippet by ID.
41+
42+
What Can This Do
43+
----------------
44+
45+
It depends on your imagination.
46+
47+
The most common usage is, feed snippet list to a fuzzy finder like Fzf_, we can search the snippet by fuzzy keywords. Once we get the snippet ID, we can access all its meta information, view its source code, edit its corresponding file, open its corresponding HTML documentation...
48+
49+
Which means, you can integrate your most handy tools with Sphinx by writing scripts. We also provide some examples about this, please refer to :ref:`integration`.
50+
51+
.. _Fzf: https://github.com/junegunn/fzf
52+
2053
Installation
2154
============
2255

23-
Download it from official Python Package Index:
56+
1. Download it from official Python Package Index:
57+
58+
.. code-block:: console
59+
60+
# pip install sphinxnotes-snippet
61+
62+
2. Make sure you have ``snippet`` command in your ``$PATH``
63+
3. Add extension to :file:`conf.py` in your Sphinx project:
64+
65+
.. code-block:: python
66+
67+
extensions = [
68+
#
69+
'sphinxnotes.snippet.ext',
70+
#
71+
]
72+
73+
4. Rebuild documentation, then invoke ``snippet stat``, the project name is expected to be seen in output.
74+
75+
.. _integration:
76+
77+
Integration
78+
===========
79+
80+
Currently we provide integration for Bash, Zsh, and Vim, you can use the following fucntion after you activated the corresponding configuration (see subsections).
81+
Beside, Fzf_ is always required.
82+
83+
Fast Edit
84+
:Shortcut: :kbd:`Ctrl+k,e`
85+
86+
Fuzzy find snippet with Fzf_ and edit corresponding file with vim
87+
88+
.. note:: :kbd:`Ctrl+k,e` means: Press :kbd:`Ctrl+k` first, then press :kbd:`e` immediately, same below
89+
90+
Fast View HTML
91+
:Shortcut: :kbd:`Ctrl+k,u`
92+
93+
Fuzzy find snippet with Fzf_ and open its corresponding HTML URL with xdg-open
94+
95+
.. note:: Before use this function, you should configurate ``base_url`` in CLI tool :ref:`cli-conf`
2496

25-
.. code-block:: console
97+
Bash
98+
----
2699

27-
$ pip install sphinxnotes-snippet
100+
Add the following code to your :file:`~/.bashrc`:
28101

29-
Add extension to :file:`conf.py` in your sphinx project:
102+
.. code-block:: bash
30103
31-
TODO
104+
eval "$(snippet integration --sh --sh-binding)"
32105
33-
.. code-block:: python
106+
Zsh
107+
---
34108

35-
extensions = [
36-
#
37-
'sphinxnotes.snippet.ext',
38-
#
39-
]
109+
Add the following code to your :file:`~/.zshrc`:
40110

111+
.. code-block:: zsh
41112
42-
.. _Configuration:
113+
eval "$(snippet integration --zsh --zsh-binding)"
114+
115+
Fast edit demo:
116+
117+
.. asciinema:: /_assets/zsh.cast
118+
119+
Vim
120+
---
121+
122+
Add the following code to your :file:`~/.vimrc`:
123+
124+
.. code-block:: vim
125+
126+
let snippet_vim = tempname()
127+
call system('snippet integration --vim --vim-binding>' . snippet_vim)
128+
execute 'source ' . snippet_vim
129+
call delete(snippet_vim)
130+
131+
Fast edit demo:
132+
133+
.. asciinema:: /_assets/vim.cast
134+
135+
Usage
136+
=====
137+
138+
.. _ext:
43139

44140
Extension
45-
=========
141+
---------
142+
143+
Append ``sphinxnotes.snippet.ext`` to Sphinx extensions.
46144

47145
Configuration
48-
-------------
146+
~~~~~~~~~~~~~
49147

50148
The extension provides the following configuration:
51149

52-
:snippet_config: (Type: ``Dict[str,Any]``, Default: ``{}``)
53-
Configuration of snippet cli command.
150+
:snippet_config:
151+
:Type: ``Dict[str,Any]``
152+
153+
Custom CLI tool :ref:`cli-conf`.
154+
155+
.. attention:: Maybe deprecated in future
156+
157+
:snippet_patterns:
158+
:Type: ``Dict[str,List[str]]``
159+
:Default: ``{'*': ['.*']}``)
160+
161+
A "snippet tags" → "regular expression list" mapping.
162+
163+
If a snippet's tags are not included in the dict, or the snippet's docname_ does not matched by the any of regular expression of corresponding list, it wil be filtered.
164+
165+
The default vaule ``{'*': ['.*']}`` matchs any snippet.
54166

55-
:snippet_patterns: (Type: ``Dict[str,List[str]]``, Default: ``{}``)
167+
.. note:: See `snippet --help` for available snippet tags
56168

169+
.. _docname: https://www.sphinx-doc.org/en/master/glossary.html#term-document-name
170+
171+
.. _cli:
57172

58173
Command Line Tool
59-
=================
174+
-----------------
175+
176+
See ``snippet --help`` for usage.
177+
178+
.. _cli-conf:
179+
180+
Configuration
181+
~~~~~~~~~~~~~
182+
183+
The configuration of CLI tools is a python script, located at :file:`$XDG_CONFIG_HOME/sphinxnotes/snippet/conf.py`, Usually :file:`~/.config/sphinxnotes/snippet/conf.py`.
184+
185+
:cache_dir:
186+
:Type: ``str``
187+
:Default: ``"$XDG_CACHE_HOME/sphinxnotes/snippet"``
188+
189+
Path to snippet cache directory.
60190

61-
A python script named :file:`snippet` should be installed in your path.
62-
(Usually :file:`/usr/local/bin` or :file:`~/.local/bin`).
191+
:base_url:
192+
:Type: ``Dict[str,str]``
193+
:Default: ``{}``
194+
195+
A "project name" → "base URL" mapping. It is used as prefix of snippet URL when you invoke ``snippet get --url <SNIPPET_ID>``
196+
197+
Base URL can point to your Sphinx site or local HTML file. For local file, URL should use "file://" schema (required by ``xdg-open``), such as: "file:///home/la/documents/bullet/_build/html/".
198+
199+
.. note:: Project name is the `project confval`_ of your Sphinx project.
200+
201+
.. _project confval: https://www.sphinx-doc.org/en/master/usage/configuration.html?highlight=project#confval-project
63202

64-
Invoke ``snippet --help`` for usage.
65203

66204
Change Log
67205
==========
68206

207+
2021-08-?? 1.0
208+
--------------
209+
210+
.. sectionauthor:: Shengyu Zhang
211+
212+
The first stable version is out, enjoy~
213+
69214
2021-03-20 1.0b2
70215
----------------
71216

doc/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/requirements.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# deps of sphinxnotes-snippet
2+
langid
3+
jieba
4+
python-pinyin
5+
pyxdg
6+
stopwordsiso
7+
wcwidth
8+
wordsegment
9+
10+
# deps of documentation
11+
sphinxcontrib.asciinema

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
'jieba',
5454
'python-pinyin',
5555
'pyxdg',
56-
'summa',
5756
'stopwordsiso',
5857
'wcwidth',
5958
'wordsegment',

0 commit comments

Comments
 (0)