代码显示块_如何在中显示代码块

代码显示块

以及如何编写内联代码和嵌入代码以突出显示语法 (And how to write inline code and embed code for syntax highlighting)

Medium makes it easy to add code blocks and inline

中号可轻松添加代码块和内联

中号有一个隐藏的快捷方式,可以将文本变成纯文本… (Medium has a hidden shortcut that will turn text plain text…)

if (developer === true) {

如果(开发人员=== true){

follow(this.mediumPublication);

按照(this.mediumPublication);

}

}

……变成格式化的代码块: (…into a formatted code block:)
if (developer === true) {
follow(this.mediumPublication);
}

To accomplish this, select the text, then push:

为此,请选择文本,然后按:

  • Windows: Control + Alt + 6

    Windows :Control + Alt + 6

  • Mac: Command + Option + 6

    Mac :Command + Option + 6

  • Linux: Control + Alt + 6

    Linux :Control + Alt + 6

Update October 19, 2016: Medium also now supports the common convention of starting a code block with triple back-ticks. If you type ``` on a new line, Medium will now switch to code input mode. A huge thanks to Luke Esterkyn and the rest of the Medium team for implementing this!

2016年10月19日更新: Medium现在还支持使用三重向后标记来启动代码块的通用约定。 如果您在新行上输入```,那么M​​edium将立即切换到代码输入模式。 非常感谢Luke Esterkyn和中型团队的其他成员!

You can also highlight code inline by selecting it, then clicking the backtick key (`). For example, you can format text as code freeCodeCamp()right in the middle of a sentence.

您也可以通过选择内联代码,然后单击反引号(`)来突出显示内联代码。 例如,您可以在句子中间直接将文本格式设置为代码freeCodeCamp()

You can also embed GitHub gists by pasting their URL into a blank line, then pressing enter:

您还可以通过将GitHub要点粘贴到空白行中,然后按Enter键来嵌入GitHub要点:

如何嵌入网络应用 (How to Embed web apps)

As a bonus, you can embed runnable apps right into Medium. Just in case these don’t render properly in Medium’s mobile apps, I recommend including links below each of the embeds as a fallback.

另外,您可以将可运行的应用程序直接嵌入Medium。 以防万一这些内容无法在Medium的移动应用中正确呈现,我建议在每个嵌入下方添加链接作为后备。

Paste a CodePen.io URL into Medium, then hit enter:

将CodePen.io URL粘贴到Medium中,然后按Enter:

View my CodePen here.

在这里查看我的CodePen。

You can also do this with JSFiddle.net:

您也可以使用JSFiddle.net做到这一点:

View my JSFiddle here.

在这里查看我的JSFiddle。

但是不要使用代码图像。 (But don’t use images of code.)

Even though it may seem convenient to take screenshots of your code and paste them into Medium, don’t do this.

尽管获取代码的屏幕快照并将其粘贴到Medium中似乎很方便,但不要这样做。

Medium doesn’t yet have an alt-text option, so this will make your code completely inaccessible to developers who are visually impaired. And yes, they are out there.

中型还没有替代文本选项,因此这将使视力障碍的开发人员完全无法访问您的代码。 是的, 他们在那里

You also can’t change the font size of a static images, which makes it a pain to read on a mobile phone (which is where most people read Medium).

您也无法更改静态图像的字体大小,这使得在手机上阅读(大多数人在其中阅读中文字的位置)感到痛苦。

Finally, this makes it impossible for readers to copy and paste your code.

最后,这使读者无法复制和粘贴您的代码。

I know, I know — you shouldn’t copy and paste code anyway.

我知道,我知道-无论如何您都不应该复制和粘贴代码。

But let’s face it — people do. And most people will quickly abandon your tutorial if faced with the prospect of manually typing out lots of code.

但让我们面对现实吧-人们做到了。 如果面临手动键入大量代码的前景,大多数人会很快放弃您的教程。

So to recap:

总结一下:

  • use Medium’s native code blocks

    使用Medium的本机代码块
  • or embed GitHub gists

    或嵌入GitHub要点
  • use working examples from CodePen and JSFiddle where possible

    尽可能使用来自CodePen和JSFiddle的工作示例
  • but don’t paste images of code

    但不要粘贴代码图像

Happy coding and writing about coding!

祝您编码愉快,写有关编码的文章!

I only write about programming and technology. If you follow me on Twitter I won’t waste your time. ?

我只写关于编程和技术的文章。 如果您在Twitter上关注我,我不会浪费您的时间。

翻译自: https://www.freecodecamp.org/news/how-to-add-code-to-medium-and-get-syntax-highlighting-d699761a5883/

代码显示块

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值