ラインブロックを後続のラインブロックと組み合わせる

ラインブロックを後続のラインブロックと組み合わせる

レッスンスライドからエクスポートされたいくつかのテキストを処理するためにpdf2textを使用しようとしています。一部のスライドの主な内容は次のとおりです。

title for the list
-
-
-
a bullet point text
another bullet point text
yet another bullet point text
- nested bullet point
- another nested bullet point
- yet another nested bullet point
title for the next list

次のように正しい(マークダウン)リストにリンクしたいと思います。

title for the first list

-   a bullet point text
-   another bullet point text
-   yet another bullet point text
    -   nested bullet point
    -   another nested bullet point
    -   yet another nested bullet point

title for the next list

ベストアンサー1

私はbashスクリプトを使っていました。

#!/bin/bash
c=0
[[ $# -eq 0 ]] && { echo "Error: Please Specify Input file" >&2; exit 1; }

while read line
do
        if [[ $line = "-" ]]; then
                (( c++ ))
                if [[ $c -eq 1 ]]; then
                    echo ""
                fi
        elif [[ $line != "" ]] && [[ $c -ne 0 ]]; then
                echo "-   ${line}"
                (( c-- ))
                if [[ $c -eq 0 ]]; then
                    echo ""
                fi
        elif [[ $line =~ "- " ]] && [[ $c -ne 0 ]]; then
                echo "    $line"
        else
                echo "$line"
        fi
done < $1

テストおよび使用された入力の例。

おすすめ記事