Upgrade to Pro — share decks privately, control downloads, hide ads and more …

素材の良さを活かしつつ、reST をReveal.jsに変換してみる話 / Converting pure reST to Revealjs

attakei
November 28, 2018

素材の良さを活かしつつ、reST をReveal.jsに変換してみる話 / Converting pure reST to Revealjs

SphinxCon JP 2018 のトーク枠で発表した、内容のPDF版です。

オリジナル版はReveal.jsのスライドとなっており、現在は以下のURLで公開されています。
https://attakei.gitlab.io/slides/talks/sphinxcon-jp-2018/

attakei

November 28, 2018
Tweet

More Decks by attakei

Other Decks in Programming

Transcript

  1. こうする SkipNode を投げなくすることで、中身をそのまま出せるよう にする visit_comment , depart_comment で中身を aside タグで囲

    めばスピーカーノートの出来上がり def visit_comment(self, node: comment): self.body.append('<aside class="notes">\n def depart_comment(self, node: comment): self.body.append('</aside>\n')
  2. どうする? code-block は literal_block を作るのだが、中はそこそこ 複雑なことをしている reveal.js的には highlight.js に任せたいので、簡略化するの が一番速そう

    sphinx.writers.html5.HTML5Translator より def visit_literal_block(self, node): # type: (nodes.Node) -> None if node.rawsource != node.astext(): # most probably a parsed-literal bloc return BaseTranslator.visit_literal_b lang = node.get('language', 'default')
  3. こうする やってることはスピーカーノートのときとおおむね同じ literal_block は language 属性を持つので、引き継ぐとよ い def visit_literal_block(self, node:

    literal_b lang = node['language'] self.body.append( f'<pre><code data-trim data-noescape def depart_literal_block(self, node: literal_ self.body.append('</code></pre>\n')
  4. htmlビルドでの挙動 <div class="section" id="title"> <h1>Title<a class="headerlink" href="#title <div class="section" id="section-1">

    <h2>Section 1.<a class="headerlink" href= <div class="section" id="content-1-1"> <h3>Content 1.1.<a class="headerlink" h </div> <div class="section" id="content-1-2"> <h3>Content 1.2.<a class="headerlink" h </div> </div>
  5. pseudoxmlにする <section ids="title" names="title"> <title> Title <section ids="section-1" names="section\ <title>

    Section 1. <section ids="content-1-1" names="con <title> Content 1.1. <section ids="content-1-2" names="con <title>
  6. どうする? title から次の section までを section として囲んで、スラ イドにしたい docutils.writers._html_base.HTMLTranslator def

    visit_section(self, node): self.section_level += 1 self.body.append( self.starttag(node, 'div', CLASS='sec def depart_section(self, node): self.section_level -= 1 self.body.append('</div>\n')
  7. こうする section の入り際で「そのセクションの最初の子セクションに」 を仕切りとする def visit_section(self, node: section): self.section_level +=

    1 if self.section_level == 1: self._proc_first_on_section = True self.body.append('<section>\n') return if self._proc_first_on_section: self._proc_first_on_section = False self.body.append('</section>\n') self.body.append(f"<section {attrs}>\n") if has child sections(node, 'section'):