rasendubi / uniorg

An accurate Org-mode parser for JavaScript/TypeScript
https://oleksii.shmalko.com/uniorg
GNU General Public License v3.0
256 stars 25 forks source link

Adding className if heading is a todo #46

Closed ispringle closed 2 years ago

ispringle commented 2 years ago

This conditionally adds a className of "todo-item" to headings which contain a TODO face. This will allow for better styling controls, as currently there isn't a way to selectively style headings that are TODO items separately from headings that are not TODO items. This should result in a familiar output compared to org-export, which does mark headings with TODO items with an additional class.

ispringle commented 2 years ago

You are right, standard org-export does not include the class name "TODO" in a heading with a todo item. I will have to figure out why my org-export does include this. Might be htmlize, I seem to have some number of addtional class names in my output.

rasendubi commented 2 years ago

Could you post an example input, what command you use to transform to html, and html output. And maybe your org/emacs config if it's public. I'll try to figure out what's adding these classes

codecov-commenter commented 2 years ago

Codecov Report

Merging #46 (8de1932) into master (c6fdf0d) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master      #46   +/-   ##
=======================================
  Coverage   95.93%   95.93%           
=======================================
  Files          15       15           
  Lines        1622     1623    +1     
  Branches      522      532   +10     
=======================================
+ Hits         1556     1557    +1     
  Misses         65       65           
  Partials        1        1           
Impacted Files Coverage Δ
packages/uniorg-rehype/src/org-to-hast.ts 97.61% <100.00%> (+0.01%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

rasendubi commented 2 years ago

Hey. Would like to know what's adding this class in your org setup before I merge this PR. If that is some well-known tool / common setup, it makes sense to merge into uniorg-rehype; if that is uncommon, I would rather do that via a plugin (e.g., use unist-util-visit to visit all heading nodes and set node.data.hProperties.className to todo-item. hProperties is copied to html properties by uniorg-rehype).

ispringle commented 2 years ago

What would the plugin route look like? I got around to looking at my org-export and this is coming from some hacks I put into the org-html-template so it's non-standard. I guess I added that and forgot all about it... 🤦‍♂️

rasendubi commented 2 years ago

Should be something like this (not tested):

import visit from 'unist-util-visit';

unified()
  .use(uniorgParse)
  .use(() => (tree) => {
    visit(tree, 'headline', (node) => {
      if (node.todo) {
        const data = node.data || {};
        const hProperties = data.hProperties || {};
        hProperties.className = 'todo-headline';
      }
    })
  })
  .use(uniorgRehype)