小编dek*_*oss的帖子

BSL(如何设计程序):如何将代码从单独的文件导入到定义区域?

我遇到了 BSL 问题。我想将我的代码分成单独的辅助文件并使用

\n\n
(require "auxiliary-function.rkt") \n
Run Code Online (Sandbox Code Playgroud)\n\n

首先将分离的代码导入到定义区域。然而它并没有像想象的那样工作。虽然没有给出明确的错误,但似乎 DrRacket 根本看不到单独文件中的代码,而我看到的只是错误

\n\n
<auxiliary-function-name>: this function is not defined \n
Run Code Online (Sandbox Code Playgroud)\n\n

显然,

\n\n
(provide x)\n
Run Code Online (Sandbox Code Playgroud)\n\n

不包含在 BSL 中。我已经阅读了手册这个答案,但 xe2x80x99s 仍然不清楚如何进行这项工作。这在 BSL 中可能吗?

\n\n

谢谢!

\n

racket racket-student-languages

3
推荐指数
1
解决办法
335
查看次数

在 Node.js 中使用 htmlparser2 选择 html 节点的文本内容

我想使用 Node.js 的htmlparser2模块解析一些 html。我的任务是通过 ID 找到精确的元素并提取其文本内容。

我已阅读文档(相当有限),并且知道如何使用该onopentag函数设置解析器,但它只允许访问标签名称及其属性(我看不到文本)。该ontext函数从给定的 html 字符串中提取所有文本节点,但忽略所有标记。

这是我的代码。

const htmlparser = require("htmlparser2");
const file = '<h1 id="heading1">Some heading</h1><p>Foobar</p>';

const parser = new htmlparser.Parser({
  onopentag: function(name, attribs){
    if (attribs.id === "heading1"){
      console.log(/*how to extract text so I can get "Some heading" here*/);
    }
  },
   
  ontext: function(text){
    console.log(text); // Some heading \n Foobar
  }
});

parser.parseComplete(file);
Run Code Online (Sandbox Code Playgroud)

我期望函数调用的输出为'Some heading'. 我相信有一些明显的解决方案,但不知何故它忽略了我的想法。

谢谢。

javascript parsing html-parsing node.js

2
推荐指数
1
解决办法
7494
查看次数