Module: CLIMarkdown::TaskPaper

Extended by:
Colors
Defined in:
lib/mdless/taskpaper.rb

Constant Summary collapse

TASK_RX =
/^(?<indent>(?:    |\t)*?)(?<marker>-)(?<task>\s+\S.*?)$/
PROJECT_RX =
/^(?<indent>(?:    |\t)*?)(?<project>[^- \t].*?:)(?<tags> @\S+)*$/
NOTE_RX =
/^(?<indent>(?:    |\t)+)(?<note>(?<!- ).*?(?!:))$/

Constants included from Colors

Colors::COLORS, Colors::ESCAPE_REGEX

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Colors

blackout, c, last_color_code, size_clean, uncolor, uncolor!, wrap

Class Attribute Details

.theme=(value) ⇒ Object (writeonly)

Sets the attribute theme

Parameters:

  • value

    the value to set the attribute theme to.



11
12
13
# File 'lib/mdless/taskpaper.rb', line 11

def theme=(value)
  @theme = value
end

Class Method Details

.color(key) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mdless/taskpaper.rb', line 13

def color(key)
  val = nil
  keys = key.split(/[ ,>]/)
  if @theme.key?(keys[0])
    val = @theme[keys.shift]
  else
    @log.error("Invalid theme key: #{key}") unless keys[0] =~ /^text/
    return c([:reset])
  end
  keys.each do |k|
    if val.key?(k)
      val = val[k]
    else
      @log.error("Invalid theme key: #{k}")
      return c([:reset])
    end
  end
  if val.is_a? String
    val = "x #{val}"
    res = val.split(/ /).map(&:to_sym)
    c(res)
  else
    c([:reset])
  end
end

.highlight(input, theme) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mdless/taskpaper.rb', line 51

def highlight(input, theme)
  @theme = theme
  mc = color('taskpaper marker')
  tc = color('taskpaper task')
  pc = color('taskpaper project')
  nc = color('taskpaper note')

  input.gsub!(PROJECT_RX) do
    m = Regexp.last_match
    "#{m['indent']}#{pc}#{m['project']}#{m['tags']}"
  end

  input.gsub!(TASK_RX) do
    m = Regexp.last_match
    "#{m['indent']}#{mc}- #{tc}#{m['task']}"
  end

  input.gsub!(NOTE_RX) do
    m = Regexp.last_match
    "#{m['indent']}#{nc}#{m['note']}"
  end

  input
end

.is_taskpaper?(input) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mdless/taskpaper.rb', line 39

def is_taskpaper?(input)
  projects = input.split(PROJECT_RX)
  tasks = 0
  if projects.count > 1
    projects.each do |proj|
      tasks += proj.scan(TASK_RX).count
    end
  end

  tasks >= 6
end