更新格式化代码
This commit is contained in:
parent
5e58c924a8
commit
2d979ebfce
|
@ -299,6 +299,9 @@ open System.Linq
|
||||||
inherit AstObject(bind)
|
inherit AstObject(bind)
|
||||||
new(bind: XmlElement) = Program(bind, [])
|
new(bind: XmlElement) = Program(bind, [])
|
||||||
|
|
||||||
|
member this.dirPath() =
|
||||||
|
bind.GetAttribute "dir_src"
|
||||||
|
|
||||||
member this.time() =
|
member this.time() =
|
||||||
bind.GetAttribute "time"
|
bind.GetAttribute "time"
|
||||||
member this.children() = objs
|
member this.children() = objs
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
namespace FmtStruct
|
namespace FmtStruct
|
||||||
|
|
||||||
|
open System.IO
|
||||||
open AstAccess
|
open AstAccess
|
||||||
open HtmlStruct
|
open HtmlStruct
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ open HtmlStruct
|
||||||
let text_type_childs = text_childs|> List.map(fun n-> n:?> Content.TextContent)
|
let text_type_childs = text_childs|> List.map(fun n-> n:?> Content.TextContent)
|
||||||
let sections = text_fmt (prefix+" ") (objref.rows()) text_type_childs
|
let sections = text_fmt (prefix+" ") (objref.rows()) text_type_childs
|
||||||
|
|
||||||
$"{prefix}{{@情节 {objref.storyRef()}&{objref.sliceRef()}{sections}}}"
|
$"\n{prefix}{{@情节 {objref.storyRef()}&{objref.sliceRef()}{sections}}}"
|
||||||
|
|
||||||
|
|
||||||
// 格式化Slice:Node
|
// 格式化Slice:Node
|
||||||
|
@ -85,7 +86,7 @@ open HtmlStruct
|
||||||
let subs = match contents with
|
let subs = match contents with
|
||||||
| [] -> ""
|
| [] -> ""
|
||||||
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
||||||
$"{prefix}{{情节 {obj_def.name()}{subs}\n{prefix}}}"
|
$"\n{prefix}{{情节 {obj_def.name()}{subs}\n{prefix}}}"
|
||||||
|
|
||||||
|
|
||||||
// 格式化Story:Node
|
// 格式化Story:Node
|
||||||
|
@ -112,7 +113,7 @@ open HtmlStruct
|
||||||
let subs = match contents with
|
let subs = match contents with
|
||||||
| [] -> ""
|
| [] -> ""
|
||||||
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
||||||
$"{{故事 {obj_story.name()}{subs}\n}}"
|
$"\n{{故事 {obj_story.name()}{subs}\n}}"
|
||||||
|
|
||||||
|
|
||||||
// 格式化Article:Node
|
// 格式化Article:Node
|
||||||
|
@ -139,7 +140,7 @@ open HtmlStruct
|
||||||
let subs = match contents with
|
let subs = match contents with
|
||||||
| [] -> ""
|
| [] -> ""
|
||||||
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
||||||
$"{prefix}{{章节 {obj_article.name()}{subs}\n{prefix}}}"
|
$"\n{prefix}{{章节 {obj_article.name()}{subs}\n{prefix}}}"
|
||||||
|
|
||||||
|
|
||||||
// 格式化Volume:Node
|
// 格式化Volume:Node
|
||||||
|
@ -166,10 +167,10 @@ open HtmlStruct
|
||||||
let subs = match contents with
|
let subs = match contents with
|
||||||
| [] -> ""
|
| [] -> ""
|
||||||
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
|
||||||
$"{{分卷 {obj_volume.name()}{subs}\n}}"
|
$"\n{{分卷 {obj_volume.name()}{subs}\n}}"
|
||||||
|
|
||||||
|
|
||||||
let document_def_fmt(path:string)(nodes: Present.IDomUnit list):string =
|
let document_def_fmt(path:string)(nodes: Present.IDomUnit list): unit =
|
||||||
let head_str, rest_nodes=match nodes.Head with
|
let head_str, rest_nodes=match nodes.Head with
|
||||||
| :? Content.RankDefine ->
|
| :? Content.RankDefine ->
|
||||||
rank_fmt(nodes.Head.object()), nodes.Tail
|
rank_fmt(nodes.Head.object()), nodes.Tail
|
||||||
|
@ -183,13 +184,16 @@ open HtmlStruct
|
||||||
story_def_fmt sdef
|
story_def_fmt sdef
|
||||||
| _ -> failwith "error-doc-child"
|
| _ -> failwith "error-doc-child"
|
||||||
)
|
)
|
||||||
head_str + (nodes_str|> List.reduce(fun a b -> a + "\n" + b))
|
let xcontent = head_str + (nodes_str|> List.reduce(fun a b -> a + "\n" + b))
|
||||||
|
use wr = new StreamWriter(path,false)
|
||||||
|
wr.Write(xcontent)
|
||||||
|
|
||||||
|
|
||||||
let program_def_fmt(nodes: Present.IDomUnit list):string list =
|
|
||||||
|
let program_def_fmt(dir:string)(nodes: Present.IDomUnit list): unit =
|
||||||
let ranks = nodes|> List.filter(fun n -> n:?Content.RankDefine)
|
let ranks = nodes|> List.filter(fun n -> n:?Content.RankDefine)
|
||||||
|
|
||||||
let content_with_rank = ranks|> List.map(fun rankn ->
|
ranks|> List.iter(fun rankn ->
|
||||||
let rank_o = rankn.object() :?> AstImport.RankDef
|
let rank_o = rankn.object() :?> AstImport.RankDef
|
||||||
let file_path = rank_o.filePath()
|
let file_path = rank_o.filePath()
|
||||||
|
|
||||||
|
@ -200,7 +204,7 @@ open HtmlStruct
|
||||||
| :? Content.VolumeDefine ->
|
| :? Content.VolumeDefine ->
|
||||||
n.object().filePath() = file_path
|
n.object().filePath() = file_path
|
||||||
| _ -> false)
|
| _ -> false)
|
||||||
document_def_fmt file_path (rankn::nodes_within)
|
document_def_fmt (Path.Combine(dir, file_path)) (rankn::nodes_within)
|
||||||
)
|
)
|
||||||
|
|
||||||
let nodes_hangout = nodes|> List.filter(fun n ->
|
let nodes_hangout = nodes|> List.filter(fun n ->
|
||||||
|
@ -214,9 +218,8 @@ open HtmlStruct
|
||||||
let path_hangout = nodes_hangout|> List.map(fun n -> n.object().filePath())
|
let path_hangout = nodes_hangout|> List.map(fun n -> n.object().filePath())
|
||||||
|> List.distinct
|
|> List.distinct
|
||||||
|
|
||||||
let content_without_rank = path_hangout |> List.map(fun path ->
|
path_hangout |> List.iter(fun path ->
|
||||||
let nodes_within = nodes_hangout|> List.filter(fun n -> n.object().filePath() = path)
|
let nodes_within = nodes_hangout|> List.filter(fun n -> n.object().filePath() = path)
|
||||||
document_def_fmt path nodes_within
|
document_def_fmt path nodes_within
|
||||||
)
|
)
|
||||||
|
|
||||||
content_with_rank@content_without_rank
|
|
||||||
|
|
|
@ -71,9 +71,7 @@ let source_format (file_in:FileInfo): unit =
|
||||||
|
|
||||||
// 获取内容节点
|
// 获取内容节点
|
||||||
let nodes = visitor.contents()
|
let nodes = visitor.contents()
|
||||||
let strings = program_def_fmt nodes
|
program_def_fmt (prog.dirPath()) nodes
|
||||||
for it in strings do
|
|
||||||
printfn $"{it}"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue