HelpNDoc 8.0.0.187-将每Pascal脚本插入当前主题位置-如何



我试图将Snippet保存到TMemoryStream中,希望可以插入当前主题的流。流是二进制形式的——当我把流写入硬盘时,我看到了它。这是我的HelpNDoc Pascal引擎代码库的代码条。参数";内容";代表当前HTML主题文本:

function getCustomHintBoxCode(content: String): String;
var _idx: Integer;
var _txt: String ;
var _tmp: String ;
var _str: String ;
var _arr: THndLibraryItemsInfoArray;
var _inf: THndLibraryItemsInfo;
const _hintbox = 'hintbox';
const _snippet = 'snippet'; 
begin
_arr := HndLibraryItems.GetItemList([7]);  // 7 = Snippets
_str := content;
for _idx := 0 to Length(_arr) - 1 do
begin
_inf := _arr[ _idx ];
_tmp := Trim( Copy(_inf.Caption,Length(_snippet)+2,64));
if (LowerCase(Copy(_inf.Caption,1,7)) = _snippet) then
begin
HndLibraryItems.GetItemContent(_inf.id).SaveToFile('E:out.tmp');
showmessage('0: ' + _tmp);
end;
end;
result := _str; 
end;

有没有办法将流直接保存到现有主题的当前位置?或者:流可以保存为HTML或Text吗?

我用多种方法解决了这个问题:

  1. 我已经向项目库添加了一个名为"的变量;hintbox_ 1";

  2. 我将占位符字符串设置为"0";pophtml";

  3. 我添加了一个新的变量:;enum->HintBox=001|HintBox=0.002|。。。

  4. 我在子目录"中创建001.html文件;。\助手";

  5. 我将Pascal模板";topics.pas.htm"文件,所以它符合我的需要。字符串";HintBox1=";将被切割并休息";001〃;字符串,我添加了";。html";,所以我得到:";001.html";。

  6. 让我们编译该项目,将文件001.html的文本提供给我主题位置,通过替换文本。

我的助手功能显示如下:

// ------------------------------------------------------------------------
// this is the root path of the HelpNDoc documentation
// files. Some sub-folders will be include later ...
// ------------------------------------------------------------------------ 
const BASE_PATH = 'E:HelpNDocmozilla';
// ------------------------------------------------------------------------
// @brief  Get the variable, that is set in the content text (editor), and
//         give back the contents of the variable that was defined in the
//         template settings.
//
// @param  content - String: Body text for current topic.         
//
// @return String, that would be append to the current position of compiler
//         processor. It replace the "hintbox" variable with files that will
//         be involved as external files.
//
// @author Jens Kallup
// ------------------------------------------------------------------------
function getCustomHintBoxCode(content: String): String;
var _idx: Integer;
var _len: Integer;
var _txt: String ;
var _tmp: String ;
var _str: String ;
var _arr: THndLibraryItemsInfoArray;
var _inf: THndLibraryItemsInfo;
var _lst: TStringList;
const _hintbox = 'hintbox';
begin
_arr := HndLibraryItems.GetItemList([5]);
_str := content;
for _idx := 0 to Length(_arr) - 1 do
begin
_inf := _arr[ _idx ];
_tmp := Trim( Copy(_inf.Caption,Length(_hintbox)+2,64));
if (LowerCase(Copy(_inf.Caption,1,7)) = _hintbox) then
begin
_tmp := HndLibraryItems .GetItemContentAsText (_inf.id);
_txt := HndGeneratorInfo.GetCustomSettingValue(_tmp);
_txt := StringReplace(_txt,'HintBox=','',[rfReplaceAll]);
_txt := _txt + '.html';
_lst := TStringList.Create;
try
try
_lst.LoadFromFile(BASE_PATH + 'helpers' + _txt);
except
on E: Exception do begin
ShowMessage('Error occur during read the file: ' + #13#10 +
BASE_PATH + 'helpers' + _txt);
end;
end;
if _lst.Count > 0 then
begin
_str := StringReplace(
_str,                // old content
_tmp,                // mark
_lst.Text,           // new text
[rfReplaceAll]);
end; 
finally
_lst.Clear;
_lst.Free;
end;
end;
end;
result := _str; 
end;

这给我带来了优势,可以在内容编辑器中设置微小的变量名称,而不是像Snippets这样的大框。。。你会喜欢的:-(

我希望这对其他人有用。代码为beerware。所以,请公平地使用代码,并对本文做一点说明。

最新更新