ReSTful underline in Nikola

Some­times you want to un­der­line some­thing. *i­tal­ic­s* bzw. <em>i­­tal­ic­s</em> just switch­es to an ital­ics iver­sion of your font. You can fix that with CSS; but what if you want both?

This is how to do it in my blog sys­tem (Niko­la):

  • in plu­g­in­s/un­der.­­plug­in:

     name = rest_un­der
     mod­ule = un­der
     com­pil­er = rest
     plug­in­cat­e­go­ry = Com­pil­erEx­ten­sion
     au­thor = Matthias Urlich­s
     ver­sion = 0.1
     web­site = http­s://­matthias.urlich­
     de­scrip­tion = Un­der­Line the marked tex­t
  • in plu­g­in­s/un­

    # -*- cod­ing: ut­f-8 -*- 
     # Copy­right © 2015 Matthias Urlichs 
     """reST role for un­der­lin­ing.""" 
     from   do­cu­tils   im­port   nodes 
     from   do­cu­til­s.­parser­s.rst   im­port   roles 
     from   niko­la.­plug­in_­cat­e­gories   im­port   Res­tEx­ten­sion 
     class   Plug­in(Res­tEx­ten­sion): 
           """­Plu­g­in for doc role.""" 
           name   =   'rest_un­der' 
           def   set_site(self,   site): 
               """Set Niko­la site.""" 
               roles.reg­is­ter_­canon­i­cal_­role('u',   un­der­_­role) 
               re­turn   su­per(Plug­in,   self).set_site(site) 
     def   un­der­_­role(name,   raw­text,   text,   lineno,   in­lin­er, 
                    op­tions={},   con­tent=[]): 
           """­Gen­er­ate a un­der­line-­class em­pha­sis.""" 
           op­tions   =   dict(**op­tions) 
           op­tions['class­es']   =   ['un­der­line'] 
           re­turn   [nodes.em­pha­sis(raw­text,   text,   *con­tent,   **op­tions)],[] 
  • in files/as­set­s/c­ss/­­cus­­tom.c­ss:

    em.un­der­line   {   font-style:   nor­mal;   tex­t-dec­o­ra­tion:   un­der­line;   } 
  • … et voilà, you can now un­der­­line.

    … et voilà, you can now  :u:`un­der­line`.

You're wel­come.


Comments powered by Disqus