本文主要描述如何将notepad++中的语法着色代码复制到word,再通过word将这些代码按照原格式

发布到博客园;

1、首先使用notepad++打开源代码文件,这里使用lua文件做演示,以下是代码在notepad++中的截图:

注意:代码的缩进请严格使用制表符,如上头中的,否则代码排版将会无缩进;

2、将代码复制到word中:

3、将代码粘贴到word中,显示:

package.cpath = "luaclib/?.so"
package.path = "lualib/?.lua;myexample/eg1/?.lua"

if _VERSION ~= "Lua 5.3" then
    error "Use lua 5.3"    
end

local socket = require "client.socket"

local fd = assert(socket.connect("127.0.0.1", 8888))

socket.send(fd, "Hello world")
while true do
    --
接收服务器返回消息

    local str = socket.recv(fd)
    if str~=nil and str~="" then
            print("server says: "..str)
            -- socket.close(fd)
            -- break;
    end

    --
读取用户输入消息
    local readstr = socket.readstdin()
    if readstr then
        if readstr == "quit" then
            socket.close(fd)
            break;
        else
            --
把用户输入消息发送给服务器
            socket.send(fd, readstr)
        end
    else
        socket.usleep(100)
    end
end
过来的代码行底色是黄色,选中黄色底色的代码,点击word中的:

将底色变为无色,显示如下:

package.cpath = "luaclib/?.so"
package.path = "lualib/?.lua;myexample/eg1/?.lua"

if _VERSION ~= "Lua 5.3" then
    error "Use lua 5.3"    
end

local socket = require "client.socket"

local fd = assert(socket.connect("127.0.0.1", 8888))

socket.send(fd, "Hello world")
while true do
    --
接收服务器返回消息

    local str = socket.recv(fd)
    if str~=nil and str~="" then
            print("server says: "..str)
            -- socket.close(fd)
            -- break;
    end

    --
读取用户输入消息
    local readstr = socket.readstdin()
    if readstr then
        if readstr == "quit" then
            socket.close(fd)
            break;
        else
            --
把用户输入消息发送给服务器
            socket.send(fd, readstr)
        end
    else
        socket.usleep(100)
    end
end
然后将代码行末尾的替换为

为了代码的一体性看起来舒适,给代码加上底纹:

package.cpath = "luaclib/?.so"
package.path = "lualib/?.lua;myexample/eg1/?.lua"

if _VERSION ~= "Lua 5.3" then
    error "Use lua 5.3"    
end

local socket = require "client.socket"

local fd = assert(socket.connect("127.0.0.1", 8888))

socket.send(fd, "Hello world")
while true do

    --
接收服务器返回消息
    local str = socket.recv(fd)
    if str~=nil and str~="" then
            print("server says: "..str)
            -- socket.close(fd)
            -- break;
    end

    --
读取用户输入消息
    local readstr = socket.readstdin()
    if readstr then
        if readstr == "quit" then
            socket.close(fd)
            break;
        else
            --
把用户输入消息发送给服务器
            socket.send(fd, readstr)
        end
    else
        socket.usleep(100)
    end
end


然后发布到博客园中;

 

 

 

转载于:https://www.cnblogs.com/skiing886/p/7695566.html

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐