9

我需要在我的网站上发布 SAS 代码。但是,如果我确实编写 HTML 来突出显示SAS鳕鱼,那将花费我很长时间。

如何将 SAS 代码转换为漂亮的HTML对应代码?

4

13 回答 13

5

我只需从您的编辑器复制/粘贴到能够生成 HTML 文件的富文本编辑器(即 MS Word 或类似编辑器)中。或者,一些文本编辑器(如UltraEdit)能够进行 SAS 标记。

于 2013-08-04T01:16:33.307 回答
5

我刚刚发现 Gist 实际上支持 SAS 语法突出显示!

hello_world.sas如果您在 Gist 上创建文件,这就是您所看到的。

在此处输入图像描述

如果您想将 SAS 代码嵌入(比如说)一篇 Wordpress.org 博客文章(比如我自己),我通常这样做的方式是:

  1. 在Gist上创建一个 Markdown 文件。例如,请参阅我创建的这个 Gist Markdown 文件)。请注意,为您创建了一个“嵌入链接”:

在此处输入图像描述

  1. 在您的 Wordpress.org 网站中,已经安装了插件oEmbed Gist

  2. 当您在 Wordpress 中创建新博客文章时,在正文字段中(您通常会在此处输入博客文章的内容),只需将 Gist 嵌入链接复制并粘贴到正文中即可。

在此处输入图像描述

  1. 发布那篇博文,你会看到它渲染得很漂亮!

在此处输入图像描述

(或者,如果您希望正常编写 Wordpress 博客文章,并嵌入多个 Gist SAS 代码,只需将 gist 文件保存为.sas文件(而不是一个.md文件),并嵌入多个嵌入 URL(对应于每个代码博客)。

更多信息请参见这个 stackoverflow 论坛——在那里我了解了很棒的 Gist 和 Wordpress Gist oEmbed 组合!

于 2016-03-13T14:57:10.880 回答
2

SAS Entreprise Guide v5.1 开始,您可以右键单击编辑器窗口并选择“将 HTML 源代码复制到剪贴板”。

然后,您可以将 HTML 直接粘贴到页面的 HTML 源代码中。

请注意,这甚至可能适用于早期版本的SAS 企业指南- 5.1 版恰好是我安装的版本。

感谢@otto提供了使用企业指南的原始想法。

于 2016-02-11T00:20:23.237 回答
1

我没有找到很好的解决方案。任何 javascript 荧光笔似乎都不支持 SAS。

我所知道的至少三个文本编辑器可以将彩色 HTML 导出到剪贴板(因此也可以导出您的页面、Word 或 PowerPoint)。

  1. 超编辑
  2. 记事本++
  3. Emacs (ESS)(在 Mac 上我使用 Aquamacs)
  4. (可能)SAS 增强编辑器......对此不确定。

另一种可能性是 Mac 上的 TextWrangler,它可以使用 SAS 语法着色文件。但我没有试过这个。[更新:这不是很好。许多关键字丢失。

第五个可能性是 SublimeText 3。它有一个很棒的语法着色插件。它甚至得到 y = X * z ;* 但这确实是一条评论;颜色正确。默认情况下不包含 SAS 着色包,但可从implementation-vdw.blogspot.ch/2012/10/new-sublime-text-package-available-for.html下载

试用版是免费的,ST是跨平台的]

有点跑题了——但下一个问题是:-)

为了准备论文和文件,有一个 LaTeX 包列表(如果您使用 BeraMono 而不是 Courier,则可以使用)和一个基于它的新包,称为 SASnRdisplay。这些包产生很好的输出,并且很容易添加关键字。此外,对于列表,您需要使用sensitive=false 选项允许小写关键字。

于 2013-11-15T15:56:39.943 回答
1

您可以使用企业指南吗?

当我从 EG 编辑窗口复制并粘贴到支持富文本(word、outlook 电子邮件等)的内容中时,我得到了所有颜色和突出显示。

从这里,您只需获取 HTML 并将其粘贴到网上。它可能不是最漂亮的 HTML(所见即所得的输出很少),但它确实有效。在 Outlook 2010 中,您可以右键单击任何已发送/接收的邮件并“查看源代码”(或者作为一种技巧,您可以将其粘贴到空白电子邮件中,然后将其关闭并在“草稿”文件夹中查看源代码) .

正如我所说,它是一些丑陋的 HTML(并且都在一行上),但我假设任何 javascript 荧光笔的输出也相当丑陋:

<b><span style='font-family:"Courier New";color:navy;background:white'>data</span></b><span style='font-family:"Courier New";color:black;background:white'> test;<o:p></o:p></span></p><p class=MsoNormal style='mso-layout-grid-align:none;text-autospace:none'><span style='font-family:"Courier New";color:black;background:white'><span style='mso-spacerun:yes'>&nbsp; </span></span><span style='font-family:"Courier New";color:blue;background:white'>set</span><span style='font-family:"Courier New";color:black;background:white'> test;<o:p></o:p></span></p><p class=MsoNormal style='mso-layout-grid-align:none;text-autospace:none'><span style='font-family:"Courier New";color:black;background:white'><span style='mso-spacerun:yes'>&nbsp; </span></span><span style='font-family:"Courier New";color:blue;background:white'>length</span><span style='font-family:"Courier New";color:black;background:white'> fakevar $</span><b><span style='font-family:"Courier New";color:teal;background:white'>16</span></b><span style='font-family:"Courier New";color:black;background:white'>;<o:p></o:p></span></p><p class=MsoNormal><b><span style='font-family:"Courier New";color:navy;background:white'>run</span></b><span style='font-family:"Courier New";color:black;background:white'>;</span><o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p>

你可以在这里看到它的渲染: http ://rendera.heroku.com/usercode/9e1bfaeb9bceb4c052d6747e8e73c1846bad433b

于 2014-05-10T16:06:36.000 回答
1

我认为您可以执行以下操作:

<script src="https://gist.github.com/AlyssonJalles/b22bc10a707ef909024b.js"></script>

*也许这不是 100% 的解决方案,但很好,因为当您在 Gist 上更新代码时,代码将在您的网站中更新。此外,如果您使用 wordpress.com,您只需复制 URL 并粘贴到您的页面编辑器中即可查看代码。

于 2015-03-07T23:39:02.653 回答
1

如果您正在创建自己的 HTML 页面(并且发现不合需要的 gist 解决方案),请查看 CodeMirror。

http://codemirror.net/mode/sas/index.html

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  mode: 'sas',
  styleActiveLine: true,
  lineNumbers: true,
  readOnly: true
});
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/codemirror.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/codemirror.min.js"></script>

<!-- sas language mode -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/mode/sas/sas.min.js"></script>

<!-- optional plugins -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/addon/selection/active-line.min.js"></script>

<form><textarea id="code" name="code">
libname foo "/tmp/foobar";
%let count=1;

/* Multi line
Comment
*/
data _null_;
    x=ranuni();
    * single comment;
    x2=x**2;
    sx=sqrt(x);
    if x=x2 then put "x must be 1";
    else do;
        put x=;
    end;
run;

/* embedded comment
* comment;
*/

proc glm data=sashelp.class;
    class sex;
    model weight = height sex;
run;

proc sql;
    select count(*)
    from sashelp.class;

    create table foo as
    select * from sashelp.class;

    select *
    from foo;
quit;
</textarea></form>

于 2016-08-31T02:45:13.477 回答
0

第六个答案是 pspad。其中有一个 SAS 插件来获得构建功能。

http://www.pspad.com/

SAS 工具在这里:http ://www.pspad.com/en/pspad-extensions.php?stranka=3

于 2014-03-21T14:09:16.743 回答
0

也许这个回购有帮助。

https://github.com/Jiangtang/sas.tmbundle

参考:

http://www.jiangtanghu.com/blog/2012/07/13/sublimetext2-sas/

于 2014-12-10T07:34:12.983 回答
0

Emacs 可以使用 Emacs Speaks Statistics (ESS) 做到这一点。我发现有两种上下文对编辑 SAS 代码很有用。第一个是sas-mode用于编辑整个 SAS 文件,第二个是使用其中的源代码块org-mode进行文学编程。

我强烈推荐阅读 Emacs 教程。如果您刚刚安装了 Emacs,只需打开它并按 Enter(在“Emacs 教程”链接上)。否则,按C-h t

1.安装ESS

按下M-x list-packages并通过 搜索 Emacs Speaks Statistics C-s emacs speaks statistics。按i标记要安装的软件包。按x安装所有标记的软件包。

2.加载ESS

加载 ESS 运行M-: (require 'ess-site)。有关详细信息,请参阅安装说明

SAS 模式

通过在当前缓冲区中加载 SAS 模式M-x sas-mode。这会根据您当前的主题提供语法突出显示。例如,这是一个轻主题。

带有浅色主题的 sas 模式

组织模式

通过 加载组织模式M-x org-mode<s通过键入并按下TAB以自动完成来创建源块。这将创建一个源代码块:

#+BEGIN_SRC 

#+END_SRC

然后键入sas让 Org Mode 知道源代码是 SAS 代码。

#+BEGIN_SRC sas

#+END_SRC

要在源代码块中切换语法突出显示,请运行M-: (setq org-src-fontify-natively t).

Any code within the block then takes on the syntax highlighting for SAS. The coloring is dependent on your theme. This is an example of a dark theme:

带有深色主题的组织模式示例

Org-mode allows for exporting to HTML using C-c C-e h o. With htmlize, the syntax highlighting will be exported too.

于 2016-10-04T16:13:56.773 回答
0

If you want to merely highlight the code for programming purposes, then the best option for you as highlighted above is a text editor. I have worked on SAS for close to a decade across platforms and organizations. I find the old crimson editor the best as it is freeware, is very light and supports many functions that are typically needed.

To ensure SAS specific syntax highlighting, you need to select the sas keyword and syntax files. These files are provided with installation only. Please follow the following steps 1. Install crimson editor (i am using version 3.70) 2. Click on Tools->Preferences->File->Syntax Type 3. In the syntax type, select the button with three dots on bottom right. It will give you a pop up and select sas.spc 4. In the Keywords, select the button with three dots on bottom right. It will give you a pop up and select sas.key 5. In the description type SAS 6. In the Top right frame/panel, select SAS from the last option And you are good to go

Edit: The Crimson Editor can be obtained from http://www.crimsoneditor.com/

于 2018-06-24T07:16:54.780 回答
0

An old question an an old programming language, but maybe somebody (like me) is still interested in yet another answer:

How to generate SAS code highlighting using Notepad++

  1. There is a [https://blogs.sas.com/content/sasdummy/2017/08/25/npp-with-sas/] (blog entry by SAS themselves) explaining how to use syntax highlighting for SAS code in Notepad++. It basically refers to a freely available Notepad++ plugin at https://github.com/cjdinger/sas-npp

  2. The next step is optional: You can export the highlighted code from Notepad++ to HTML using the NppExport plugin, see e.g. https://www.addictivetips.com/windows-tips/nppexport-for-notepad-export-highlighted-code-in-html-rtf-format/

How to highlight SAS code in VIM

关于如何使用 VIM 编辑 SAS 代码的 SAS 社区有一个很好的介绍:http: //www.sascommunity.org/planet/blog/category/vim/

基本思想是你获得一个 VIM 的语法定义文件并安装它,见 https://www.vim.org/scripts/script.php?script_id=1999

于 2019-05-07T10:57:02.300 回答
-1

要突出显示宏中的文本,请输入以下行:

%macro __enable_eg_syntax_highlight; %mend __enable_eg_syntax_highlight;

所以在一切都是黑色的地方,上面的行将带回 SAS 格式。

问候特里

于 2016-06-23T09:32:33.220 回答