PlainTasksとJSONのプラグインの開発

9815 ワード

PlainTasksは有名なタスク管理プラグインで、具体的にはここに紹介されています.
私の最近の仕事は、JSONファイルからtodoクラスファイルへの変換を実現するプラグインを開発することです.
JSONのフォーマットはこうです
   1:  {
   2:     "project2":[
   3:        {
   4:           "finish_time":"",
   5:           "status":0,
   6:           "name":"marking a  sublime demo"
   7:        },
   8:        {
   9:           "finish_time":"",
  10:           "status":0,
  11:           "name":"testing"
  12:        },
  13:        {
  14:           "finish_time":"",
  15:           "status":0,
  16:           "name":"programing"
  17:        }
  18:     ],
  19:     "project1":[
  20:        {
  21:           "finish_time":"",
  22:           "status":0,
  23:           "name":"writing a  blog"
  24:        },
  25:        {
  26:           "finish_time":"",
  27:           "status":0,
  28:           "name":"reading a book"
  29:        },
  30:        {
  31:           "finish_time":"",
  32:           "status":0,
  33:           "name":"go to home"
  34:        }
  35:     ]
  36:  }


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
以下は一部のコードの断片で、pythonの文法が大好きですが、私は深くありません.
   1:   def conver_todo_json(self):
   2:          file_name = self.window.active_view().file_name()
   3:          if not ".todo" in file_name:
   4:              return
   5:   
   6:          rom = '^\s*☐\s*(.*)$'
   7:          rdm = '\s*\✔\s*(.+?)\s*@done?([\(\)\d\w,\.:\-/ ]*)\s*'
   8:          rpm = '([^\b\(]*?)(?=\:)'
   9:   
  10:          json_data = {}
  11:          json_file = re.sub("\.todo", '.json', file_name)
  12:          project = 'other'
  13:   
  14:          with open(file_name, "r+", encoding="utf-8") as f:
  15:              for line in f:
  16:                  prj = re.match(rpm, line)
  17:                  if prj:
  18:                      project = prj.groups()[0]
  19:                      json_data[project] = []
  20:                  task_open = re.match(rom, line)
  21:                  if task_open:
  22:                      task_item = {"name": task_open.groups()[0] ,"status":0,"finish_time":""}
  23:                      json_data[project].append(task_item)
  24:                  task_done = re.match(rdm, line)
  25:                  if task_done:
  26:                      task_item = {"name":task_done.groups()[0],"status":1,"finish_time":task_done.groups()[1] }
  27:                      json_data[project].append(task_item)
  28:   
  29:          with open(json_file, "w+", encoding="utf-8") as f:
  30:              json.dump(json_data, f)
  31:   
  32:          self.window.open_file(json_file)


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
詳細はここ