Environment construction memo to satisfy the desire
OS X Marverics
Python2.7
virtualenv(virtualenvwrapper)
pip
Sphinx
homebrew
Pandoc
Apache
Kobito.app <= 1.9.2
"External file linkage" cannot be used temporarily for Kobito 2.0 series
Dash.app
Alfred.app
Anyway, prepare a Sphinx project
$ mkvirtualenv qiitanote #I'm using virualenvwrapper
(qiitanote)$ pip install Sphinx
(qiitanote)$ mkdir qiitanote
(qiitanote)$ cd qiitanote
(qiitanote)$ sphinx-quickstarpt
#You can hear various things in the dialogue, so if you answer a little, the creation is over
#try make html
(qiitanote)$ make html
# _build/html/HTML document is generated below
#Turn off Virtualhost with Apache and http://qiitanote.dev/so_build/I am trying to see below html
#Check the document(Chrome opens)
(qiitanote)$ open -a Google\ Chrome.app http://qiitanote.dev
Initial directory structure
qiitanote
├── Makefile
├── _build
│ ├── doctrees
│ └── html <-HTML is generated here
├── _static
├── _templates
├── conf.py <-Sphinx config file
└── index.rst
Pandoc Insco
(qiitanote)$ brew install pandoc
Extension settings
# conf.Rewrite py
#Added the following contents
PROJECT_DIR = os.path.dirname(__file__)
sys.path.insert(0, PROJECT_DIR)
sys.path.insert(0, os.path.join(PROJECT_DIR, "libs")) #Extension script installed under libs
extensions += ["sphinxcontrib_markdown"]
markdown_title = 'Qiita Note'
source_suffix = '.md'
Create a .md file and write it
(qiitanote)$ touch fisrtnote.md
contents
# My First Qiita Memo!!!
## 1. Hoge
hogehogehogehoge
hogehogehogehoge
## 2. Fuga
fugafugafugafuga
fugafugafugafuga
Build
(qiitanote)$ make html
result
Make files work with Kobito for posting to Qiita
(qiitanote)$ open -a Kobito firstnote.md
# -*- coding: utf-8 -*-
import os
import time
import subprocess
TARGET_DIR = os.path.join(os.path.dirname(__file__), '..')
cmd = "open --hide -g -a Kobito {}"
# start Koibito.app
subprocess.call(cmd.format(""), shell=True)
time.sleep(3)
# associate .md file to Koibito.app
for root, dirs, files in os.walk(TARGET_DIR):
for f in files:
if f.endswith(".md"):
f = os.path.abspath(os.path.join(root, f))
subprocess.call(cmd.format(f), shell=True)
# hyde Kobito.app
subprocess.call(
"osascript -e 'tell application \"Finder\"'"
" -e 'set visible of process \"Kobito\" to false'"
" -e 'end tell'",
shell=True
)
Make this script run when you "make html"
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
python libs/associate_kobito.py # <=add to
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
When you build with this, a memo will appear in Kobito without permission.
Configuration so far
qiitanote
├── Makefile
├── _build
│ ├── doctrees
│ └── html
├── _static
├── _templates
├── conf.py
├── firstnote.md
├── index.md # <-add to
├── index.rst
└── libs
├── associate_kobito.py # <-add to
└── sphinxcontrib_markdown.py # <-add to
It's a memo I wrote, so I want to search it easily at hand. Search using Alfred and Dash. I bought both Alfred and Dash for a fee.
sphinxcontrib-dashbuilder makes it easy to turn Sphinx documents into Docsets for Dash
Installation
(qiitanote)$ pip install sphinxcontrib-dashbuilder
Change configuration file
# conf.py
extensions += ["sphinxcontrib_markdown", "sphinxcontrib.dashbuilder"]
dash_name = 'QiitaNote'
dash_icon_file = '_static/qiita.png' # <-The favicon was properly brought from Qiita
Rewriting Makefile
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
DOCSETSDIR = ~/Library/Application\ Support/Dash/DocSets/QiitaNote # <-add to
~abridgement~
# .Added dash to PHONY
.PHONY: dash help ...
~abridgement~
#Add dash target
dash:
$(SPHINXBUILD) -b dash $(ALLSPHINXOPTS) $(DOCSETSDIR)
@echo
@echo "Build finished. The Docset are in $(DOCSETSDIR)."
Build
(qiitanote)$ make dash
Check with Dash. Dash settings screen> Docsets> Press the Rescan button
Qiita Note appears in Dash's Docsets
It is troublesome to hit "make dash" every time, so build dash even when "make html".
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
$(SPHINXBUILD) -b dash $(ALLSPHINXOPTS) $(DOCSETSDIR) # <-add to
python libs/associate_kobito.py
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
Markdown-> reST Forces the heading to index during conversion.
## Hoge
## Fuga
Suppose you have a headline like this. When converted to reST, do as follows.
.. index:: Hoge
Hoge
----
.. index:: Fuga
Fuga
----
Add the following process to libs / sphinxcontrib_markdown.py.
48 # insert index directive
49 newlines = []
50 for line in source[0].split(u"\n"):
51 if self._is_heading_line(line):
52 prev = newlines[-1]
53 inedexline = u".. index:: {0}\n".format(prev)
54 newlines.insert(-1, inedexline)
55 newlines.append(line)
56 source[0] = "\n".join(newlines)
Now when you build again you can find the heading from Alfred
Configuration so far
qiitanote
├── Makefile
├── _build
│ └── doctrees
├── _static
│ └── qiita.png # <-add to
├── _templates
├── conf.py
├── firstnote.md
├── index.md
├── index.rst
└── libs
├── associate_kobito.py
└── sphinxcontrib_markdown.py
Use my sphinx theme.
(qiitanote)$ pip install sphinxjp.themes.basicstrap
Change settings
# conf.py
extensions += ["sphinxcontrib_markdown", "sphinxcontrib.dashbuilder", 'sphinxjp.themes.basicstrap']
html_theme = 'basicstrap'
html_theme_options = {
'noheader': True,
'header_inverse': True,
'relbar_inverse': True,
'inner_theme': True,
'inner_theme_name': 'bootswatch-sandstone',
}
Build
(qiitanote)$ make html
result
It's a little different from what is written, but I put it on Github. Please accept it.
https://github.com/tell-k/qiitanote
TODO
Recommended Posts