2012-01-19 27 views
-1

我有一個項目,其中大量的技術規範當前是作爲HTML文件「發佈」的。 HTML文件不是託管在Web服務器上,而是被壓縮並分發到PC的本地文件系統中進行訪問。Pre將HTML文件編譯爲靜態文件發佈

我在探索創建「發佈」系統的想法,發佈商可以根據HTML本身內的自定義標籤修改HTML文件的內容。我想這與使用PHP或ASP(如果它是基於服務器的)類似。

因此,例如,我想補充

<Publisher action="___" params="________" /> 

出版商將檢測的「標籤」做必要的處理,然後注入所需HTML到更換標記文件的存在。

有沒有人知道使用基於.NET的技術或其他方式來實現這一點的方法來實現相同的事情。

+0

您可能可以使用一個asp.net viewengine。 – CodesInChaos

回答

0

好吧,不知道這是否是最優雅的解決方案,它的工作原理。

1)基於Cannot delete directory with Directory.Delete(path, true)我清除了發佈的「網站」打算去的目標。

2)然後我使用基於接受的解決方案的代碼將所有文件複製到問題Copy the entire contents of a directory in C#

3)我攔截所有的「HTM」或「HTML」文件,並使用正則表達式來查看是否需要「處理」。這是基於這裏的代碼http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace(v=vs.71).aspx(如下所示)

using System.Text.RegularExpressions; 

class RegExSample 
{ 
    static string CapText(Match m) 
    { 
    // Get the matched string. 
    string x = m.ToString(); 
    // If the first char is lower case... 
    if (char.IsLower(x[0])) 
    { 
     // Capitalize it. 
     return char.ToUpper(x[0]) + x.Substring(1, x.Length-1); 
    } 
    return x; 
    } 

    static void Main() 
    { 
    string text = "four score and seven years ago"; 
    System.Console.WriteLine("text=[" + text + "]"); 
    string result = Regex.Replace(text, @"\w+", 
     new MatchEvaluator(RegExSample.CapText)); 
    System.Console.WriteLine("result=[" + result + "]"); 
    } 
}