Skip to content

Instantly share code, notes, and snippets.

@jiangtao
Last active July 31, 2017 09:34
Show Gist options
  • Save jiangtao/1e2571d0c293cfb4416cc42c3cae366f to your computer and use it in GitHub Desktop.
Save jiangtao/1e2571d0c293cfb4416cc42c3cae366f to your computer and use it in GitHub Desktop.

Revisions

  1. jiangtao revised this gist Jul 31, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions convert.sh
    Original file line number Diff line number Diff line change
    @@ -3,20 +3,23 @@ from="src"
    to="dist"
    type="docx"

    # 检测brew
    if ! command -v brew >/dev/null 2>&1; then
    echo "brew没有安装,请安装"
    exit 0
    fi

    # 检测pandoc
    if ! command -v pandoc >/dev/null 2>&1; then
    brew install pandoc
    fi


    # 检测 from
    if [ ! -d $from ]; then
    echo "src不存在"
    exit 0
    fi

    # 检测 to
    if [ ! -d $to ]; then
    mkdir $to
    fi
    @@ -29,8 +32,6 @@ if [ $count == 0 ]; then
    exit 0
    fi



    cd $from

    list=$(ls | grep ${type})
    @@ -41,5 +42,4 @@ for doc in $list
    mv ${doc/${type}/html} "../${to}"
    done

    echo -e "src下所有的docx文件转换成html成功"

    echo "src下所有的docx文件转换成html成功"
  2. jiangtao revised this gist Jul 31, 2017. 1 changed file with 40 additions and 3 deletions.
    43 changes: 40 additions & 3 deletions convert.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,45 @@
    #!/bin/bash
    from="src"
    to="dist"
    type="docx"

    if ! command -v brew >/dev/null 2>&1; then
    echo "brew没有安装,请安装"
    exit 0
    fi

    if ! command -v pandoc >/dev/null 2>&1; then
    brew install pandoc
    fi

    if [ ! -d $from ]; then
    echo "src不存在"
    exit 0
    fi

    if [ ! -d $to ]; then
    mkdir $to
    fi

    # 检测src下是否含有docx
    count=$(ls $from | grep ${type} | wc -l)

    if [ $count == 0 ]; then
    echo "src为空, 请放置文档到src目录下"
    exit 0
    fi



    cd $from

    list=$(ls | grep ${type})
    targetType="html"

    for doc in $list
    do
    pandoc -s ${doc} -t ${targetType} -o ${doc/${type}/${targetType}}
    done
    pandoc -s ${doc} -t html -o ${doc/${type}/html}
    mv ${doc/${type}/html} "../${to}"
    done

    echo -e "src下所有的docx文件转换成html成功"

  3. jiangtao renamed this gist May 27, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. jiangtao created this gist May 27, 2017.
    8 changes: 8 additions & 0 deletions sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #!/bin/bash
    type="docx"
    list=$(ls | grep ${type})
    targetType="html"
    for doc in $list
    do
    pandoc -s ${doc} -t ${targetType} -o ${doc/${type}/${targetType}}
    done