-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.lua
49 lines (42 loc) · 1 KB
/
file.lua
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
package.path=package.path..";./luagy/?.lua"
Class=require("grammar.class")
require("Penlight.lua.pl.stringx").import()
--[[
代表一个文件或者目录
]]
--@class
local File=Class(function ( self ,filepath)
--public:
self.filename=filepath or ""
self.Descript=""
self.attr={}
end)
--public:
function File:toString()
return ((self.filename):ljust(20," "))..(((self.Descript~="") and self.Descript ) or "Not has Descript")
end
--解析md的字符串
function File:initFromMDstr(str)
if not str:startswith("*") then
self.parseSuccess=false
return
end
con=str:split('`')
if(con:len()~= 3 ) then
self.parseSuccess=false
return
end
self.filename=con[2]
c=con[3]
endl=con[3]:lfind("|") and con[3]:lfind("|")-1 or #c
self.Descript=c:sub(1,endl):strip()
self.parseSuccess=true
--todo:tag
end
function File:toMDstr()
str="* "
str=str.."`"..self.filename.."` "
str=str..self.Descript
return str
end
return File