首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HelpNDoc 8.0.0.187 -将每个Pascal脚本片段插入到当前主题位置-如何?

HelpNDoc 8.0.0.187 -将每个Pascal脚本片段插入到当前主题位置-如何?
EN

Stack Overflow用户
提问于 2022-08-26 01:58:29
回答 1查看 36关注 0票数 1

我试图将一个片段保存到一个TMemoryStream中,希望能在当前主题上插入流。流是二进制格式的-我看到它,当我将流写到我的硬盘。下面是我的HelpNDoc Pascal引擎代码库的代码条。参数"content“表示当前的HTML主题文本:

代码语言:javascript
复制
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或文本吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-26 03:52:58

我以多种方式解决了这个问题:

  1. I向项目添加了一个变量-库,名称为"hintbox_1"

  1. I将占位符字符串设置为"pophtml"

  1. I添加了一个新的变量:"enum -> HintBox=001 HintBox=002 \.

  1. I在子目录".\helpers"

中创建001.html文件

  1. I更改Pascal-模板"topics.pas.htm“文件,以满足我的需要。字符串"HintBox1=“将被剪切,rest "001”字符串将添加".html",因此我得到:"001.html".

  1. ,让我们编译这个项目,通过替换text.

,将文件001.html的文本放到当前主题位置

我的助手函数显示如下:

代码语言:javascript
复制
// ------------------------------------------------------------------------
// this is the root path of the HelpNDoc documentation
// files. Some sub-folders will be include later ...
// ------------------------------------------------------------------------ 
const BASE_PATH = 'E:\HelpNDoc\mozilla\';

// ------------------------------------------------------------------------
// @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;

这给我带来的好处是,在内容编辑器中设置微小的变量名,而不是像代码片段这样的大胖框,.你会喜欢的:-)

我希望这对任何其他人都有帮助。代码以beerware的形式出现。因此,请公平地使用这段代码,并注意这篇文章。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73495354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档