- a task list item
- list syntax required
- normal formatting, @mentions, #1234 refs
- incomplete
- completed
-
-
Save roktas/94a22939d3845c589f421aed38fe2e00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'colorize' | |
module ParseUtils | |
TASK_ELEMENT_REGEX = /(?m:^- \[( |X|x)\] (.*)$)/ | |
BOLD_REGEX = /[*][*]([^*]+)[*][*]/ | |
ITALIC_REGEX = /\*([^\*]+)\*/ | |
FENCED_REGEX = /`([\S]+)`/ | |
module_function | |
def parse(src) | |
m = src.match TASK_ELEMENT_REGEX | |
text = src | |
checked = false | |
if m | |
text = m[2] | |
checked = %w(x X).include?(m[1]) ? true : false | |
end | |
yield text, checked if block_given? | |
end | |
def render(src) | |
src.gsub!(BOLD_REGEX, %(\\1).bold) if src =~ BOLD_REGEX | |
src.gsub!(FENCED_REGEX, %(\\1).light_black) if src =~ FENCED_REGEX | |
src.gsub!(ITALIC_REGEX, %(\\1).italic) if src =~ ITALIC_REGEX | |
src | |
end | |
end | |
# require 'test/unit' | |
# | |
# class TestParseUtils < Test::Unit::TestCase | |
# @@checklist_items = { | |
# '-Foo bar baz hede' => ['-Foo bar baz hede', false], | |
# '- Foo bar baz hodo' => ['- Foo bar baz hodo', false], | |
# '-[] Foo bar baz' => ['-[] Foo bar baz', false], | |
# '-[ ] Foo bar baz' => ['-[ ] Foo bar baz', false], | |
# '- [] Foo bar baz' => ['- [] Foo bar baz', false], | |
# '- [ ] Foo bar baz' => ['Foo bar baz', false], | |
# '- [_] Foo bar baz' => ['- [_] Foo bar baz', false], | |
# '- [x] Foo bar baz' => ['Foo bar baz', true], | |
# '- [X] Foo bar baz' => ['Foo bar baz', true], | |
# } | |
# @@formatting_items = { | |
# '- [ ] `Foo`' => "#{'Foo'.light_black}", | |
# '- [ ] ``Foo``' => "#{'`Foo`'.light_black}", | |
# '- [ ] *Foo*' => "#{'Foo'.italic}", | |
# '- [ ] **Foo**' => "#{'Foo'.bold}", | |
# } | |
# | |
# def test_parse | |
# @@checklist_items.each do |item, args| | |
# ParseUtils.parse(item) do |text, checked| | |
# assert_equal text, args.first | |
# assert_equal checked, args.last | |
# end | |
# end | |
# end | |
# | |
# def test_render | |
# @@formatting_items.each do |item, formatted| | |
# ParseUtils.parse(item) do |text| | |
# assert_equal ParseUtils.render(text), formatted | |
# end | |
# end | |
# end | |
# end | |
def process_line(line) | |
ParseUtils.parse(line) do |text, checked| | |
warn '✓ '.green + ParseUtils.render(text) if checked | |
warn '✕ '.red + ParseUtils.render(text) unless checked | |
end if line =~ ParseUtils::TASK_ELEMENT_REGEX | |
end | |
def main | |
fp = File.join File.expand_path('.'), 'TODO.md' | |
abort 'Bu dizinde `TODO.md` dosyası yok!' unless File.exist?(fp) | |
File.readlines(fp).each { |line| process_line(line) } | |
end | |
main if __FILE__ == $PROGRAM_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment