{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rX8mhOLljYeM"
      },
      "source": [
        "---\n",
        "\n",
        "title: Jupyter notebootk 支持（.ipynb 格式）\n",
        "keywords: teedoc, Jupyter, notebook, ipynb, 生成网页, 生成html\n",
        "tags: 语法, teedoc, jupyter\n",
        "desc: 使用 jupyter notebook 语法编写 ipynb 文件，会自动生成HTML网页\n",
        "\n",
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "本文使用 jupyter 编写（`.ipynb` 格式），源文档请点击右上角`编辑本页`查看\n",
        "\n",
        "`jupyter-notebook`插件`teedoc-plugin-jupyter-notebook-parser`默认可能没有使用， 需要在`site_config`文件中配置\n",
        "\n",
        "```json\n",
        "    \"plugins\": {\n",
        "      \"teedoc-plugin-jupyter-notebook-parser\":{\n",
        "          \"from\": \"pypi\",\n",
        "          \"config\": {\n",
        "          }\n",
        "      }\n",
        "    }\n",
        "```\n",
        "\n",
        "## Markdown 元数据头\n",
        "\n",
        "每个`md`文件可以添加一个头，也叫`metadata`（中文叫元数据），通过这些键值来设置文章信息，格式为`yaml`格式，当然这个文件头是可选的，也可以不写\n",
        "\n",
        "```markdown\n",
        "---\n",
        "title: markdown 语法\n",
        "tags: teedoc, markdown, 语法\n",
        "keywords: teedoc, markdown, 语法\n",
        "desc: teedoc 的 markdown 语法介绍和实例\n",
        "id: zh_readme\n",
        "class: zh_readme\n",
        "# 以 # 号开头表示注释\n",
        "---\n",
        "```\n",
        "\n",
        "* `title`: 文章的标题，如果没有元数据头的话，可以使用\n",
        "```markdown\n",
        "# 文章标题\n",
        "```\n",
        "或者\n",
        "```markdown\n",
        "文章标题\n",
        "===\n",
        "```\n",
        "\n",
        "* `keywords`: 关键词，多个关键词用英文逗号`,` 隔开，会被添加到`html`头中，方便搜索引擎爬取，不会显示到页面。也可以用`yaml`列表的格式写\n",
        "```markdown\n",
        "keywords:\n",
        "  - teedoc\n",
        "  - markdown\n",
        "  - 语法\n",
        "```\n",
        "* `desc`: 页面描述，会被添加到`html`头中，不会在页面显示，方便搜索引擎爬取\n",
        "* `tags`： 文章标签，会显示到页面，多个标签用英文逗号`,` 隔开，也可以用`yaml`列表的格式写，同`keywords`\n",
        "* `id`: 页面`id`， 会被添加到`html`标签中，比如`<html id=\"zh_readme\">...</html>`, 通常不需要，一般在对某个页面单独自定义`css`的时候可能会用上，会覆盖`config.json`中的设置\n",
        "* `class`: 页面`class`,多个用英文逗号`,`隔开，可以不设置，会覆盖`config.json`中的设置。比如可以通过设置这个值来达到设置特定页面的`css`样式。具体支持的样式见[主题插件的文档](../plugins/themes.md)\n",
        "* `layout`: 页面使用的布局模板, 默认会使用主题插件里面的配置,如果你需要自定义此页面的布局, 可以设置这个参数, 路径相对于`site_config`中的`layout_root_dir`设置的路径, `layout_root_dir` 默认为`layout`, 所以要使用`layout/special_layout.html` 只需要填写`special_layout.html`. 布局模板语法见[layout 文档](../usage/layout_template.md)\n",
        "* `date`: 最后更新日期，格式如`2022-09-15`\n",
        "  * 如果不设置：默认会使用文件的最后修改时间，如果是`git`仓库，会自动从`git`获取页面最后一次提交的时间，如果没有`git`或者`git`获取失败则会从文件系统读取最后修改时间（这很可能不准确）。另外如果`update`填写了值，则会采用`update`中最新的修改日期\n",
        "  * 如果不想显示最后修改日期，通过设置值为`false`来禁用\n",
        "  * 如果设置了`update`值，仍然会优先使用`date`中的值\n",
        "* `update`: 更新历史，会在文章开头生成更新历史表格，格式：\n",
        "```markdown\n",
        "update:\n",
        "  - date: 2022-09-15\n",
        "    author: author1\n",
        "    version: 1.1.0\n",
        "    content: 更新了xxx\n",
        "  - date: 2022-08-05\n",
        "    author: author2\n",
        "    version: 1.0.0\n",
        "    content: 更新了xxx\n",
        "```\n",
        "* `update_open`: 是否默认展开更新记录，默认为 `true`，关闭设置为`false`即可。（由主题插件支持）\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3wF5wszaj97Y"
      },
      "source": [
        "## Markdown 语法\n",
        "\n",
        "Markdown 语法可以参考 [Markdown 语法](./syntax_markdown.md)，由于`jupyter`的语法解析器来自[jupyter 官方](https://github.com/jupyter/nbconvert), 可能部分`.md`文件已经支持了的语法 `jupyter`却不支持，具体可以尝试是否支持。\n",
        "\n",
        "###  三级标题\n",
        "\n",
        "#### 四级标题\n",
        "\n",
        "和 Markdown 页面相同，详情见 [Markdown 语法](./syntax_markdown.md) 页面\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 三级标题2\n",
        "\n",
        "#### 四级标题2\n",
        "\n",
        "\n",
        "## 链接\n",
        "\n",
        "[相对路径， README.md 文件](../README.md): `../README.md`， 会自动转换成`index.html`\n",
        "\n",
        "[相对路径， md 文件](./syntax_markdown.md)： `./syntax_markdown.md`， 会转成文档的 `.html` 结尾的链接\n",
        "\n",
        "[绝对路径， http 文件](https://storage.googleapis.com/tensorflow_docs/docs-l10n/site/zh-cn/tutorials/quickstart/beginner.ipynb)： `https://。。。/beginner.ipynb`，原链接，不会修改\n",
        "\n",
        "[相对路径， ipynb 文件](./syntax_jupyter.ipynb)： `./syntax_jupyter.ipynb`， 会转成文档的 `.html` 结尾的链接\n",
        "\n",
        "## 图片\n",
        "\n",
        "![](../assets/images/logo.png)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 代码\n",
        "\n",
        "以下是 python 代码，可以包含执行结果，在本地使用 `jupyter` 或者 [jupyterlab](https://jupyter.org/install) 或者 `vscode` 执行代码后 保存即可"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "hello\n"
          ]
        }
      ],
      "source": [
        "print(\"hello\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "world\n",
            "world\n"
          ]
        }
      ],
      "source": [
        "print(\"world\\nworld\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 代码输出显示图片\n",
        "\n",
        "代码输出的图片会被集成在页面中："
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "image\n"
          ]
        },
        {
          "data": {
            "image/png": "[encoded data, 114152 characters]",
            "text/plain": [
              "<Figure size 640x480 with 1 Axes>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        },
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "image\n"
          ]
        }
      ],
      "source": [
        "from PIL import Image\n",
        "img = Image.open(\"../assets/images/logo.png\")\n",
        "from matplotlib import pyplot as plt\n",
        "print(\"image\")\n",
        "plt.figure()\n",
        "plt.imshow(img)\n",
        "plt.show()\n",
        "print(\"image\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 表格\n",
        "\n",
        "\n",
        "| Header 1 | *Header* 2 |\n",
        "| -------- | -------- |\n",
        "| `Cell 1` | [Cell 2](http://example.com) link |\n",
        "| Cell 3 | **Cell 4** |\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 数学\n",
        "\n",
        "支持`tex`和`Latex`语法，以及`MathML`标签\n",
        "\n",
        "两种写法，\n",
        "* 一种是行内内嵌，用`$`符号将方程包起来，比如\n",
        "```markdown\n",
        "质能方程 $E=mc^2$大家很熟悉吧\n",
        "```\n",
        "> 效果:\n",
        "> 质能方程 $E=mc^2$大家很熟悉吧\n",
        "\n",
        "* 另一种，块方程，用`$$`将方程包起来，比如\n",
        "```markdown\n",
        "$$\n",
        "E=mc^2\n",
        "$$\n",
        "```\n",
        "> 效果:\n",
        "> $$\n",
        "> E=mc^2\n",
        "> $$\n",
        "\n",
        "其他例子：\n",
        "常见：\n",
        "```markdown\n",
        "When $a \\ne 0$, there are two solutions to $ax^2 + bx + c = 0$ and they are\n",
        "$$\n",
        "x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.\n",
        "$$\n",
        "```\n",
        "\n",
        "> When $a \\ne 0$, there are two solutions to $ax^2 + bx + c = 0$ and they are\n",
        "> $$\n",
        "> x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.\n",
        "> $$\n",
        "\n",
        "\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "collapsed_sections": [],
      "name": "beginner.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3.7.6 ('base')",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.6"
    },
    "vscode": {
      "interpreter": {
        "hash": "ffe1fa326dd7d6c3151c23694bf76d392c9e40c17f4ee23e2cf57913219b3858"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
