Slog78_本地Markdown编辑器--ArthurSLogMD!

  • ArthurSlog

  • SLog-78

  • Year·1

  • Guangzhou·China

  • September 19th 2018

微信扫描二维码,关注我的公众号

不尚贤 使民不争 不贵难得之货 使民不为盗 不见可欲 使民心不乱 是以圣人之治 虚其心 实其腹 弱其志 强其骨 常使民无知无欲 使夫智者不敢为也 为无为 则无不治


开发环境MacOS(High Sierra 10.13.6 (17G65))

需要的信息和信息源:

开始编码

  • 本篇是把ArthurSlog.com网站上的Markdown编辑器本地化了

  • 使用的是Electron,用HTML,CSS和JavaScript来构建跨平台桌面应用程序的一个开源库

  • 目前已经完成基本功能

  • 完整源码已上传至 Github: github.com/BlessedChil…

git clone github.com/BlessedChil…

cd ArthurSlogMarkdownEditor

sudo npm i --unsafe-perm=true

sudo npm run start

  • 启动rthurSlogMarkdownEditor

  • 使用Markdown语法书写,测试成功!

  • 对于electron来说,他主要是负责两件事情:

  1. 使用nodejs负责操作系统与界面之间的交互,称为主函数

  2. 调用浏览器渲染(例如V8、webkit、等)引擎负责界面的交互,成为渲染函数

  • 顾名思义,主函数是一切的开始:

~/Desktop/ArthurSlogMarkdownEditor/main.js

const { app, BrowserWindow } = require('electron')

let win

function createWindow() {
    win = new BrowserWindow({
        width: 800,
        height: 600,

    })
    win.loadFile('index.html')

    //win.webContents.openDevTools()

    win.on('closed', () => {
        win = null
    })
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
    if (process.platform == 'darwin') {
        qpp.quit()
    }
})

app.on('activate', () => {
    if (win == null) {
        createWindow()
    }
})
复制代码
  • 具体函数的作用,下次再补充了,因为我现在还有更重要的事要去做

  • 再来看一下配置文件 package.json:

~/Desktop/ArthurSlogMarkdownEditor/package.json

{
  "name": "ArthurSlogBrowser_Nodejs",
  "version": "0.0.1",
  "description": "This is a Browser by Nodejs",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "electron  ."
  },
  "keywords": [],
  "author": "ArthurSlog",
  "license": "ISC",
  "devDependencies": {
    "electron": "^2.0.9"
  },
  "dependencies": {
    "markdown-it": "^8.4.2"
  }
}
复制代码
  • 当然,界面文件index.html也需要更新一下:
<!DOCTYPE html>
<html lang="en">

<head>
    <title>ArthurSlogMD</title>
    <meta charset="UTF-8">
</head>

<body>
    <div id="container">
        <!-- ArthurSlog_Manual_Area -->
        <div id="editorManual">
            <div id="editorManual_Title">
                <p id="editorManual_Title_Arthur">Arthur</p>
                <p id="editorManual_Title_Slog">Slog</p>
                <p id="editorManual_Title_createCenter">创作中心</p>
            </div>
            <div id="editorManual_middleLine"></div>
            <div id="editorManual_Tool">
                <p>building...</p>
            </div>
        </div>
        <div id="editorContent">
            <!-- ArthurSlog_MarkdownEditor_Area -->
            <div id="sourceCode_Markdown" contenteditable="true"></div>

            <div id="middleLine"></div>
            <!-- ArthurSlog_MarkdownToHTML_AREA -->
            <div id="resultCode_HTML"></div>
        </div>
    </div>

    <script>
        require('markdown-it')
        const md = require('markdown-it')();

        document.getElementById("sourceCode_Markdown").addEventListener('input', function () {
            document.getElementById("resultCode_HTML").innerHTML = md.render(document.getElementById("sourceCode_Markdown").innerText)
        }, false);
        // target.addEventListener(type, listener, options);
        // target.addEventListener(type, listener ,{capture: Boolean, passive: Boolean, once: Boolean});
        // target.addEventListener(type, listener, useCapture);
        // target.addEventListener(type, listener[, useCapture, wantsUntrusted  ]); 
        // ---
        // 1. target = document.getElementById("basic")
        // 2. type = 'input'
        // 3. listener = document.getElementById("resultHTML").innerHTML = window.markdownit().render(document.getElementById("basic").value)
        // 4. options = false
        // =>
        // 5. target.addEventListener(type, listener, options)
        //document.getElementById("sourceCode_Markdown").addEventListener('input', function () { document.getElementById("resultCode_HTML").innerHTML = window.markdownit().render(document.getElementById("sourceCode_Markdown").innerText) }, false);
        //document.getElementById("sourceCode_Markdown").addEventListener('paste', function () { document.getElementById("sourceCode_Markdown").innerText = document.getElementById("sourceCode_Markdown").innerText.toString()}, false);
        document.getElementById("sourceCode_Markdown").style.boxShadow = "none";
        document.getElementById("sourceCode_Markdown").style.textShadow = "none";
        document.getElementById("sourceCode_Markdown").style.outlineColor = "none";
        document.getElementById("sourceCode_Markdown").style.outlineStyle = "none";
        document.getElementById("sourceCode_Markdown").style.outline = "none";
        document.getElementById("sourceCode_Markdown").style.borderColor = "none";
    </script>

    <style>
        html,
        body {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;

            max-width: 100%;
            max-height: 100%;
            overflow: hidden;
        }

        #container {
            display: flex;
            flex-direction: column;
            position: absolute;
            margin: 0;
            padding: 0;
        }

        #EditorManual {
            display: flex;
            flex-direction: column;
            position: absolute;
            margin: 0;
            height: 15vh;
        }

        #editorManual_Title {
            margin-left: 0%;
            margin-right: 0%;
            height: 9.5vh;
            display: flex;
            flex-direction: row;
        }

        #editorManual_Title_Arthur {
            font-size: 28px;
            font-style: italic;
            color: rgb(255, 0, 0);
            font-weight: 800;
            position: absolute;
            margin: 0;
            top: calc(4%);
            padding-left: 56px;
        }

        #editorManual_Title_Slog {
            font-size: 28px;
            font-style: italic;
            color: rgb(17, 1, 1);
            font-weight: 800;
            position: absolute;
            margin: 0;
            top: calc(4%);
            padding-left: 138px;
        }

        #editorManual_Title_createCenter {
            font-size: 22px;
            font-style: normal;
            font-weight: 300;
            color: rgb(114, 123, 128);
            position: absolute;
            margin: 0;
            top: calc(4% + 6px);
            padding-left: 208px;
        }

        #editorManual_middleLine {
            margin: 0;
            padding: 0;
            height: 0.5vh;
            background-color: rgba(241, 248, 255, 0.966);
        }

        #editorManual_Tool {
            margin-left: 0%;
            margin-right: 0%;
            height: 5vh;
        }

        #editorManual_Tool>p {
            font-size: 16px;
            font-style: italic;
            position: relative;
            top: calc(100% - 20px);
            margin: 0;
            padding-left: 56px;
        }

        #editorContent {
            display: flex;
            flex-direction: row;
            position: relative;
            margin: 0;
            padding: 0;
        }

        #sourceCode_Markdown {
            width: 47.5vw;
            height: 85vh;
            margin-left: 0%;
            margin-right: 0%;
            overflow: scroll;
            background-color: rgba(199, 206, 212, 0.678);
            text-decoration: none;
        }

        #middleLine {
            width: 5vw;
            height: 85vh;
            overflow: hidden;
            background-color: ghostwhite;
        }

        #resultCode_HTML {
            width: 47.5vw;
            height: 85vh;
            margin-left: 0%;
            margin-right: 0%;
            overflow: scroll;
            background-color: ghostwhite;
        }
    </style>
</body>

</html>
复制代码
  • ok,文件结构比较简单,后面在来构建指定平台的可执行文件

  • 至此,ArthurSLogMarkdownEditor编辑器本地化第一阶段 GET!。


欢迎关注我的微信公众号 ArthurSlog

微信扫描二维码,关注我的公众号

如果你喜欢我的文章 欢迎点赞 留言

谢谢

明确下:pgbouncer/lib/usual/mbuf.h 里有 _MUSTCHECK static inline bool mbuf_get_bytes(struct MBuf *buf, unsigned len, const uint8_t **dst_p) { if (buf->read_pos + len > buf->write_pos) return false; *dst_p = buf->data + buf->read_pos; buf->read_pos += len; return true; } 如下是添加了sm3处理的answer_authreq,是否正确? /* answer server authentication request */ bool answer_authreq(PgSocket *server, PktHdr *pkt) { uint32_t cmd; const uint8_t *salt; bool res = false; /* authreq body must contain 32bit cmd */ if (mbuf_avail_for_read(&pkt->data) < 4) return false; if (!mbuf_get_uint32be(&pkt->data, &cmd)) return false; switch (cmd) { case AUTH_OK: slog_debug(server, "S: auth ok"); res = true; break; case AUTH_PLAIN: slog_debug(server, "S: req cleartext password"); res = login_clear_psw(server); break; case AUTH_MD5: slog_debug(server, "S: req md5-crypted psw"); if (!mbuf_get_bytes(&pkt->data, 4, &salt)) return false; res = login_md5_psw(server, salt); break; case AUTH_SM3: slog_debug(server, "S: req sm3-crypted psw"); if (!mbuf_get_bytes(&pkt->data, SM3_SALT_LENGTH, &salt)) return false; res = login_sm3_psw(server, salt); break; case AUTH_SASL: { bool selected_mechanism = false; slog_debug(server, "S: req SASL"); do { const char *mech; if (!mbuf_get_string(&pkt->data, &mech)) return false; if (!mech[0]) break; slog_debug(server, "S: SASL advertised mechanism: %s", mech); if (strcmp(mech, "SCRAM-SHA-256") == 0) selected_mechanism = true; } while (!selected_mechanism); if (!selected_mechanism) { slog_error(server, "none of the server's SASL authentication mechanisms are supported"); kill_pool_logins(server->pool, "server login failed: none of the server's SASL authentication mechanisms are supported"); } else res = login_scram_sha_256(server); break; } case AUTH_SASL_CONT: { unsigned len; const uint8_t *data; slog_debug(server, "S: SASL cont"); len = mbuf_avail_for_read(&pkt->data); if (!mbuf_get_bytes(&pkt->data, len, &data)) return false; res = login_scram_sha_256_cont(server, len, data); break; } case AUTH_SASL_FIN: { unsigned len; const uint8_t *data; slog_debug(server, "S: SASL final"); len = mbuf_avail_for_read(&pkt->data); if (!mbuf_get_bytes(&pkt->data, len, &data)) return false; res = login_scram_sha_256_final(server, len, data); free_scram_state(&server->scram_state); break; } default: slog_error(server, "unknown/unsupported auth method: %d", cmd); res = false; break; } return res; }
最新发布
07-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值