markdown中引用代码

您是否撰写有关Javascript和Typescript的技术文章? (Do you write technical articles about Javascript and Typescript?)

Do you write blog-posts about programming and software development? Great! That means you’re sharing your knowledge with fellow developers. In your technical post, you’ll want to include source code snippets. And of course, you want your source code to work. But when you co-develop your post and your code, your code is not yet finished when you start writing. When the source code changes, the struggle of keeping the snippets up-to-date begins. It’s a challenge but there is a way out.

您是否撰写有关编程和软件开发的博客文章? 大! 这意味着您正在与其他开发人员共享知识。 在您的技术文章中,您将希望包含源代码片段。 当然,您希望您的源代码能够正常工作。 但是,当您共同开发文章和代码时,开始编写代码时代码尚未完成。 当源代码更改时,保持片段最新状态的工作就开始了。 这是一个挑战,但有一条出路。

Note: This post was created with Publishable. You'll find the source file in the example-data folder in this repository (here)

注意 :此帖子是使用Publishable创建的。 您可以在此存储库中的example-data文件夹中找到源文件( 此处 )

让我们潜入吧! (Let’s dive in!)

Let’s say that this is the source code of your index.ts:

假设这是index.ts的源代码:

/** * @helloTag * Call `sayHello` to greet a person by her name. */function sayHello (name: string) { return `Hello ${name}!` }

With Publishable, you can refer to your code in your article (in Markdown):

使用Publishable ,您可以在文章(在Markdown中)中引用您的代码:

Have a look at the source code: <Source source="index" tag="helloTag"/> <Comment source="index" tag="helloTag"/>

This is the result (in Markdown):

这是结果(在Markdown中):

```function sayHello (name: string) { return `Hello ${name}!` }```Call `sayHello` to greet a person by her name.

And this is the rendered result (it looks different depending on the renderer):

这是渲染的结果(根据渲染器的不同,它看起来也不同):

Screenshot taken from Publishable
屏幕截图取自Publishable

为什么要参考代码和注释? (Why Would I Want To Refer To Code And Comments?)

When writing technical articles about Javascript and Typescript, you’ll likely want to show some code. But how does the code get there?

在撰写有关Javascript和Typescript的技术文章时,您可能需要显示一些代码。 但是代码如何到达那里?

You copy it from your IDE and paste it into the draft of your post.

您可以从IDE复制它,然后将其粘贴到帖子草稿中。

What do you do if the code changes? (And, it will change…)

如果代码更改,该怎么办? (而且,它将改变……)

You copy it from your IDE and paste it into the draft of your post. Again!

您可以从IDE复制它,并将其粘贴到帖子草稿中。 再次!

Once you finish your technical article, you will have copied and pasted your source code so many times that it’s going to be hard to tell whether all the code is up to date, and even harder to tell whether your code and the post text are in sync.

一旦您完成了技术文章,您将复制和粘贴您的源代码很多次,以至于很难分辨所有代码是否都是最新的,甚至更难分辨您的代码和帖子文本是否在其中。同步。

When you refer to your code and your code-comments, you ensure your article contains the actual source code. The source code you wrote, tested, and found to work.

当您引用代码和代码注释时,请确保您的文章包含实际的源代码。 您编写,测试并发现有效的源代码。

安装与配置 (Installation & Configuration)

Add Publishable as a devDependency to the project that contains the source code, you'll want to write about.

Publishable作为devDependency添加到要编写的包含源代码的项目中。

npm install --save-dev publishable-tech

Publishable provides an executable script at ./node-modules/@publishable/tech/index.js

Publishable在./node-modules/@publishable/tech/index.js提供可执行脚本

Add a script to your package.json in which you call this script in NodeJs and pass start as an argument

script添加到package.json中,在其中您可以在NodeJs中调用此脚本,并将start作为参数传递

"scripts": { "publishable":   "node ./node_modules/publishable-tech/index.js start" }

Publishable looks for the publishable.config.js file in the root directory of your project (in the same directory your package.json is in).

Publishable在项目的根目录(在package.json所在的目录中)中查找publishable.config.js文件。

module.exports = { contentPath: "./example-data/content", sourcesPath: "./example-data/src"}

The configuration supports the following paths:

该配置支持以下路径:

type IPublishableConfig = {/** * The `contentPath` is the (relative to the current * working directory) * path to the user's MD-content-folder */ contentPath: string;/** * The `sourcesPath` is the (relative to the current * working directory) * path to the user's source code folder */ sourcesPath: string;};

用 (Use)

Start Publishable during development with npm run publishable.

在开发过程中使用npm run publishable启动Publishable

Publishable loads your content and your sources and starts on localhost:8080. Publishable reloads automatically, Whenever you change your code or your content. Thus, you can see any change directly.

可发布可加载内容和源,并从localhost:8080开始。 无论何时更改代码或内容,可发布内容都会自动重新加载。 因此,您可以直接看到任何更改。

Write your Javascript and Typescript code. Do it the way you like and the way you usually write your code. Like this:

编写您的Javascript和Typescript代码。 以您喜欢的方式和通常的代码编写方式进行操作。 像这样:

function sayHello (name: string) { return `Hello ${name}!`}

If you want to refer to a piece of code, add a leading comment (starting with /**) and specify an arbitrary tag (starting with an@-sign). Like this:

如果要引用一段代码,请添加一个前导注释(以/**开头)并指定一个任意标记(以@ -sign开头)。 像这样:

/** * @helloTag * Call `sayHello` to greet a person by her name. */function sayHello (name: string) { return `Hello ${name}!`}

Add a markdown (.md)-file to the folder you specified as the contentPath in the publishable.config.js.

将markdown( .md )文件添加到您指定为publishable.config.jscontentPath的文件夹中。

You can use the normal Markdown syntax. And you can use two special tags:

您可以使用普通的Markdown语法。 您可以使用两个特殊标签:

  1. The <Source />-tag adds source code snippet.

    <Source /> -tag添加源代码片段。

  2. The <Comment />-tag adds a comment.

    <Comment /> -tag添加注释。

Both components take two properties:

这两个组件都具有两个属性:

  • source specifies the source-file (without file extension) you want to add a snippet or a comment from.

    source指定要添加代码段或注释的源文件(不带文件扩展名)。

  • tag specifies the snippet or comment to include

    tag指定要包含的代码段或评论

Of course, you can only place the tag into a comment. <Source /> will include the source code block the tagged comment refers to. Comments (starting with/**) preceed code blocks they refer to.

当然,您只能将tag放入注释中。 <Source />将包含标记注释所引用的源代码块。 注释(以/**开头)位于它们所引用的代码块之前。

For example, let’s say you have the following source code:

例如,假设您具有以下源代码:

function sayGoodbye(name: string) { return `Good bye ${name}!`}/** * @helloTag * Call `sayHello` to greet a person by her name. *//** * Another comment on `sayHello` */function sayHello (name: string) { return `Hello ${name}!`}

When you use <Source source="index" tag="helloTag /> in your .md-file, it will produce the following:

当您使用<Source source="index" tag="helloTag />在你.md -file,就会产生如下:

```function sayHello (name: string) { return `Hello ${name}!`}```

And when you use <Comment source="index" tag="helloTag />, it will produce this:

当您使用<Comment source="index" tag="helloTag /> ,它将产生以下内容:

Call `

<Comment /> only includes the comment that has the specified tag. But your source code block may have more than one comment. This way, you can control the parts of your comments you include or exclude.

<Comment />仅包含具有指定标签的注释。 但是您的源代码块可能有多个注释。 这样,您可以控制要包括或排除的注释部分。

Once you finished writing your code and your article, click the Export-button you'll find at the end of your article.

完成代码和文章的编写后,请单击文章结尾处的“ Export按钮。

It resolves all the references and provides the resulting Markdown file. You can use this file as documentation on GitHub or import it on any blogging platform.

它解析所有引用并提供生成的Markdown文件。 您可以将此文件用作GitHub上的文档,也可以将其导入任何博客平台。

结论 (Conclusion)

Keeping source code snippets in your technical article up-to-date manually is cumbersome and error-prone. Publishable lets you reference your source code and its comments in Markdown. Whenever your source code changes, it keeps your snippets synchronized.

手动更新技术文章中的源代码片段既麻烦又容易出错。 可发布可让您在Markdown中引用源代码及其注释。 只要您的源代码发生更改,它就会使您的代码片段保持同步。

翻译自: https://codeburst.io/how-to-reference-your-javascript-source-code-in-markdown-2e5b2568699b

markdown中引用代码


http://www.taodudu.cc/news/show-5327570.html

相关文章:

  • Java语言使用注解处理器生成代码——第三部分:生成源代码
  • 优秀C/C++源代码网站
  • 说说那几款查看源代码的工具
  • 区分源代码包和二进制包
  • C++头文件、源代码文件简单总结
  • 个人能力模型
  • Android 项目开发 基于Web Service 服务的中英翻译软件(三) Web Service服务 Ksoap2 项目...
  • 基于单片机的光伏电量检测系统的设计1-毕设课设全套资料
  • 基于单片机的光伏电量检测系统的设计-毕设课设protues仿真
  • 无人机光伏电站检测系统
  • 光伏板异常识别算法
  • 太阳能电池板/光伏板缺陷检测数据集
  • 光伏电池板目标检测数据集
  • 光伏玻璃表面瑕疵检测系统
  • 基于Halcon学习的缺陷检测【五】光伏电池片的指纹以及划痕检测【第二种方法】
  • 基于Halcon学习的缺陷检测【四】光伏电池片的指纹以及划痕检测【第一种方法】
  • 光伏接线盒机器人视觉定位焊接检测|光伏接线盒焊接机焊接检测
  • 光伏阵列故障诊断笔记
  • MySQL故障检测_MySQL故障检测和修正的一般过程
  • 光伏发电---光伏组件“热斑效应”介绍
  • 光伏电站直流电弧故障类型-光伏直流电弧检测监测器模组应用方案
  • 未来已来,光伏产业将走向何方?十大趋势待揭晓!
  • 机器视觉技术在光伏玻璃行业中的应用:光伏玻璃表面缺陷在线检测
  • 全球最大光伏电池缺陷异常检测数据集PVELAD【发布】
  • 光伏电站无人机视觉智能检测系统
  • PCB设计3W规则、20H原则、五五规则
  • codeforces 1017D The Wu(状压+预处理)
  • java 对接webapi接口数据提交方式之 application/x-www-form-urlencoded
  • 解决Ubuntu 下域名解析出现ping: www.baidu.com: Temporary failure in name resolution及重启后/etc/resolvconf文件内容被重写
  • linux 虚拟机 ping: www.baidu.com: 未知的名称或服务 报错处理

markdown中引用代码_如何在Markdown中引用您JavaScript源代码相关推荐

  1. html中看到php代码_如何在HTML中嵌入PHP代码

    如何在HTML中嵌入PHP代码 对于一个有经验的 PHP Web 开发者,在HTML中嵌入PHP代码是一件非常容易的事情.但是对于刚开始接触 PHP 编程语言的新手这就是一个问题.下面是小编为大家带来 ...

  2. python二进制转八进制代码_如何在python中输入二进制、八进制、十进制、十六进制数据并转换...

    最近在学习python,不过跟着课本的作业题目: 分别就计算二进制110110011.八进制256和十六进制的数字a4b5,并转化为十进制求和. 不过写过程中遇到了个问题: 如何在python中输入二 ...

  3. 叉号在word中的字符代码_如何在Word中手动创建复合字符

    叉号在word中的字符代码 If you occasionally need to use mathematical symbols in your documents that aren't ava ...

  4. excel中去重计数_如何在Excel中计数

    excel中去重计数 There are lots of different ways to count things in Excel – maybe you need to count the n ...

  5. aws中部署防火墙_如何在AWS中设置自动部署

    aws中部署防火墙 by Harry Sauers 哈里·绍尔斯(Harry Sauers) 如何在AWS中设置自动部署 (How to set up automated deployment in ...

  6. 如何在mysql中创建过程_如何在MySQL 中创建存储过程?

    问题阐述 自MySQL 5.0 开始,MySQL 就支持存储过程.存储过程是一些被用户定义的SQL 语句集合.一个存储程序是可以被存储在服务器中的一套SQL 语句.存储过程可以被程序.触发器或另一个存 ...

  7. python3提取字符串中的数字_如何在Python中从字符串中提取数字?

    14 回复 | 直到 1 年前 1 430 3 年前 如果只想提取正整数,请尝试以下操作: >>> str = "h3110 23 cat 444.4 rabbit 11 ...

  8. java中为什么同步_如何在Java中同步工作

    如何在Java中同步工作 首先, 这是一个示例 : public class Deadlock { static class Friend { private final String name; p ...

  9. npm中node更新_如何在Node中管理NPM和功能时保持理智

    npm中node更新 by Ted Gross 泰德·格罗斯(Ted Gross) 如何在Node中管理NPM和功能时保持理智 (How to keep your sanity while manag ...

最新文章

  1. 11位院士专家建言基础研究
  2. 2017年9月11日
  3. kaggle竞赛--房价预测详细解读
  4. java $和$$的区别_Java #{}和${}区别
  5. 【安卓开发】AndroidStudio项目提交到github最详细步骤
  6. (3)<meta>标签
  7. iphone开发每日一练【2011-10-04】
  8. foxmail邮箱服务器类型,foxmail
  9. 计算机中b代表的含义是什么意思,表示文件大小的MB,KB,B等是什么意思?
  10. 使用github构建自己网站
  11. android 系统开启流量,安卓系统抖音流量权限怎么打开
  12. pyqt5做了一个二维码生成器,已打包成exe可执行程序...
  13. AT24Cxx读写全面理解
  14. 操作系统锁的实现方法有哪几种_深入理解多线程(四)——Moniter的实现原理...
  15. 计算机方向的综述投稿哪个期刊,人工智能方向论文投稿期刊
  16. MQTT-Eclipse paho mqtt源码分析-连接MQTT Broker
  17. 北斗导航 | ION GNSS+ 2014到 ION GNSS+ 2017会议论文下载:ION 美国导航学会
  18. python数据的存储结构是指_python数据结构
  19. 通过对比3PL和4PL,来了解什么是4PL
  20. 『数据结构』海量数据处理

热门文章

  1. IM聊天应用是如何将消息发送给对方的
  2. 信捷plc和台达变频器通信程序通过信捷xc3的modbus通信控制台达vfd-m变频器的正转
  3. YoloV5在tensorRT上加速(Windows)(C++)(webcam)
  4. 服务器集群负载均衡(F5、Array、Nginx、LVS、HAProxy)区别以及选型
  5. h5 uniapp html2canvas生成海报,保存到本地功能实现;
  6. 上海控安全新发布轨道交通系统信息安全检测工具箱
  7. 硕士剑桥大学计算机工程系排名,剑桥大学世界排名及专业排名汇总(ARWU世界大学排名版)...
  8. (B站云e办)SpringBoot开发项目实战记录(七)(员工管理(分页知识))
  9. AJAX和axios的基本使用
  10. Asp数据库访问代码自动产生工具-ASPRunner(适用初学者和为了提高开发效率的Developer)