diff --git a/AstConv/HtmlStruct.fs b/AstConv/HtmlStruct.fs index eb4761b..9c5986c 100644 --- a/AstConv/HtmlStruct.fs +++ b/AstConv/HtmlStruct.fs @@ -8,15 +8,13 @@ open System /// 可访问元素 type Access(hrefs: string) = class - member this.accessLink(): string = - hrefs + member this.accessLink(): string = hrefs end /// 回退访问元素 type Backward(hrefs: string) = class - member this.backwardLink(): string = - hrefs + member this.backwardLink(): string = hrefs end /// 内容元素:分卷、章节、引用节点、故事线、情节、定义节点、引用节点 @@ -29,11 +27,12 @@ open System /// 容器节点:分卷、章节、故事线、情节 type IContainer = interface - abstract member append:List -> IContainer + abstract member append:IDomUnit list -> IContainer + abstract member children:unit -> IDomUnit list end /// 访问页面:概括页面、卷宗页面、故事线页面、节点汇总 ================================================= - type VolumePage(page_hrefs: string, volume: IDomUnit, childs: List) = + type VolumePage(page_hrefs: string, volume: IDomUnit, childs: IDomUnit list) = class inherit Access(page_hrefs) new(page_hrefs, volume) = VolumePage(page_hrefs, volume, []) @@ -45,11 +44,12 @@ open System raise (System.NotImplementedException()) interface IContainer with - member this.append(childs: List): IContainer = + member this.children(): IDomUnit list = childs + member this.append(childs: IDomUnit list): IContainer = raise (System.NotImplementedException()) end - type StoryPage(page_hrefs: string, story: IDomUnit, childs: List) = + type StoryPage(page_hrefs: string, story: IDomUnit, childs: IDomUnit list) = class inherit Access(page_hrefs) new(page_hrefs, story) = StoryPage(page_hrefs, story, []) @@ -61,11 +61,12 @@ open System raise (System.NotImplementedException()) interface IContainer with - member this.append(childs: List): IContainer = + member this.children(): IDomUnit list = childs + member this.append(childs: IDomUnit list): IContainer = raise (System.NotImplementedException()) end - type PointPage(page_hrefs: string, point: IDomUnit, refer_list: List) = + type PointPage(page_hrefs: string, point: IDomUnit, refer_list: IDomUnit list) = class inherit Access(page_hrefs) new(page_hrefs, point) = PointPage(page_hrefs, point, []) @@ -77,7 +78,8 @@ open System raise (System.NotImplementedException()) interface IContainer with - member this.append(childs: List): IContainer = + member this.children(): IDomUnit list = refer_list + member this.append(childs: IDomUnit list): IContainer = raise (System.NotImplementedException()) end @@ -93,7 +95,7 @@ open System end - type PointRefer(refs: AstImport.PointRef, items: List) = + type PointRefer(refs: AstImport.PointRef, items: Present.IDomUnit list) = class let ref_signature = $"@{refs.storyRef()}&{refs.sliceRef()}&{refs.pointRef()}" let lines = refs.children() |> List.map (fun x->x.content()) @@ -105,7 +107,8 @@ open System raise (System.NotImplementedException()) interface Present.IContainer with - member this.append(childs: List): Present.IContainer = + member this.children(): Present.IDomUnit list = items + member this.append(childs: Present.IDomUnit list): Present.IContainer = raise (System.NotImplementedException()) end let refer_assemble (refn: AstImport.PointRef) : PointRefer = @@ -113,7 +116,7 @@ open System PointRefer(refn, texts) - type PointDefine(defs: AstImport.PointDef, items: List) = + type PointDefine(defs: AstImport.PointDef, items: Present.IDomUnit list) = class let lines = defs.children() |> List.map (fun x->x.content()) @@ -124,7 +127,8 @@ open System raise (System.NotImplementedException()) interface Present.IContainer with - member this.append(childs: List): Present.IContainer = + member this.children(): Present.IDomUnit list = items + member this.append(childs: Present.IDomUnit list): Present.IContainer = raise (System.NotImplementedException()) end let point_assemble (defs: AstImport.PointDef) : PointDefine = @@ -132,7 +136,7 @@ open System PointDefine(defs, texts) - type SliceDefine(defs: AstImport.SliceDef, items: List) = + type SliceDefine(defs: AstImport.SliceDef, items: Present.IDomUnit list) = class interface Present.IDomUnit with member this.name(): string = @@ -141,7 +145,8 @@ open System raise (System.NotImplementedException()) interface Present.IContainer with - member this.append(childs: List): Present.IContainer = + member this.children(): Present.IDomUnit list = items + member this.append(childs: Present.IDomUnit list): Present.IContainer = raise (System.NotImplementedException()) end let slice_assemble (defs: AstImport.SliceDef) : SliceDefine = @@ -156,7 +161,7 @@ open System SliceDefine(defs, childs) - type StoryDefine(defs: AstImport.StoryDef, childs: List) = + type StoryDefine(defs: AstImport.StoryDef, childs: Present.IDomUnit list) = class interface Present.IDomUnit with member this.name(): string = @@ -165,7 +170,8 @@ open System raise (System.NotImplementedException()) interface Present.IContainer with - member this.append(childs: List): Present.IContainer = + member this.children(): Present.IDomUnit list = childs + member this.append(childs: Present.IDomUnit list): Present.IContainer = raise (System.NotImplementedException()) end let story_assemble (defs: AstImport.StoryDef): StoryDefine = @@ -179,7 +185,7 @@ open System StoryDefine(defs, childs) - type ArticleDefine(defs: AstImport.ArticleDef, childs: List) = + type ArticleDefine(defs: AstImport.ArticleDef, childs: Present.IDomUnit list) = class interface Present.IDomUnit with member this.name(): string = @@ -188,7 +194,8 @@ open System raise (System.NotImplementedException()) interface Present.IContainer with - member this.append(childs: List): Present.IContainer = + member this.children(): Present.IDomUnit list = childs + member this.append(childs: Present.IDomUnit list): Present.IContainer = raise (System.NotImplementedException()) end let article_assemble (defs: AstImport.ArticleDef) : ArticleDefine = @@ -202,7 +209,7 @@ open System ArticleDefine(defs, childs) - type VolumeDefine(defs: AstImport.VolumeDef, childs: List) = + type VolumeDefine(defs: AstImport.VolumeDef, childs: Present.IDomUnit list) = class interface Present.IDomUnit with member this.name(): string = @@ -211,8 +218,9 @@ open System raise (System.NotImplementedException()) interface Present.IContainer with - member this.append(childs: List): Present.IContainer = - raise (System.NotImplementedException()) + member this.children(): Present.IDomUnit list = childs + member this.append(news: Present.IDomUnit list): Present.IContainer = + VolumeDefine(defs, childs@news) end let volume_assemble (defs: AstImport.VolumeDef): VolumeDefine = let childs = defs.children() @@ -263,4 +271,33 @@ open System member this.contents() = result_nodes |> List.map(fun (_, obj) -> obj) - end \ No newline at end of file + end + + + module Assemble = + /// 构建页面名称 + let page_address_make(node: Present.IDomUnit): string = + let name_seqs = node.name().ToCharArray() |> Array.map(fun c-> string(uint16(c))) + name_seqs |> Array.reduce(fun a b-> a+b) + + /// 构建所有卷宗页面 + let rec volume_page_build (nodes: Present.IDomUnit list): Present.VolumePage list = + match nodes with + | [] -> [] + | _ -> + match nodes.Head with + | :? Content.VolumeDefine as vole -> + let con: Present.IContainer = vole + Present.VolumePage(page_address_make(vole), vole, con.children())::volume_page_build(nodes.Tail) + | _ -> volume_page_build(nodes.Tail) + + /// 构建所有故事线页面 + let rec story_page_build (nodes: Present.IDomUnit list): Present.StoryPage list = + match nodes with + | [] -> [] + | _ -> + match nodes.Head with + | :? Content.StoryDefine as storye -> + let con: Present.IContainer = storye + Present.StoryPage(page_address_make(storye), storye, con.children())::story_page_build(nodes.Tail) + | _ -> story_page_build(nodes.Tail) \ No newline at end of file