「Markdown」の版間の差分
提供: MacWiki
(→AppleScript: 文書の最初の部分にあるメタデータを変更する) |
細 (→AppleScript: 文書の最初の部分にあるメタデータを変更する) |
||
行141: | 行141: | ||
* 文書の最初の部分にあるメタデータを変更する([[TextEdit|テキストエディット]]の最前面の文書を処理) | * 文書の最初の部分にあるメタデータを変更する([[TextEdit|テキストエディット]]の最前面の文書を処理) | ||
− | 文書の最初の部分にあるTitle等の「データ名: データ」という形式を探して見つけたら変更します。ここでは Timestamp: 2015-09-19 01:23:45 +0900 | + | 文書の最初の部分にあるTitle等の「データ名: データ」という形式を探して見つけたら変更します。ここでは Timestamp: 2015-09-19 01:23:45 +0900 のような形式のタイムスタンプを現在の日時に変更します。 |
<pre> | <pre> | ||
set newData to "Timestamp: " & (do shell script "date '+%F %T %z'") & return | set newData to "Timestamp: " & (do shell script "date '+%F %T %z'") & return | ||
− | tell front document of application "TextEdit" -- Jedit X | + | tell front document of application "TextEdit" -- ここを変えるだけで Jedit X でもそのまま動作する |
set idx to 1 | set idx to 1 | ||
repeat while paragraph idx contains ":" | repeat while paragraph idx contains ":" | ||
行166: | 行166: | ||
<pre> | <pre> | ||
set newData to "Timestamp: " & (do shell script "date '+%F %T %z'") & return | set newData to "Timestamp: " & (do shell script "date '+%F %T %z'") & return | ||
− | tell front document of application "TextEdit" -- Jedit X | + | tell front document of application "TextEdit" -- ここを変えるだけで Jedit X でもそのまま動作する |
if exists (first paragraph where it begins with "Timestamp:") then | if exists (first paragraph where it begins with "Timestamp:") then | ||
set oldData to a reference to (first paragraph where it begins with "Timestamp:") | set oldData to a reference to (first paragraph where it begins with "Timestamp:") |
2015年9月19日 (土) 13:01時点における版
Markdown とは?
Markdown は軽量マークアップ言語の1つ。詳しくは以下のところを参照して下さい。
関連するソフトウェア
Marked 2
Markdownなどの形式で書かれたUTF-8の標準テキスト(プレーンテキスト)を解釈して表示するビューアーです。拡張されたMarkdownを解釈でき、TeXをインストールしていない環境でもMathJaxを利用して数式等をきれいに表示したり、プログラミング言語のコードをシンタックスハイライトして表示することもできます。
例えば以下のような標準テキストだと、最初のTitle等のメタデータは非表示になり、数式は解釈されて表示されます。
Title: 下書き Author: わたくし Date: 2012-07-16 # <span style="color:red">二項定理</span>の話 ## はじめに \\(a\\)と\\(b\\)の和の2乗を計算すると \\[ \eqalign{ (a+b)^2 &= (a+b)(a+b) \\ &= a^2 + ab + ba + b^2 \\ &= a^2 + 2ab + b^2 } \\] となる。3乗、4乗、⋯と進めていくと、以下のようになる。 | \\(k\\) | \\((a+b)^k\\) | |:-------:|:------------------------------------------------------| | 3 | \\(a^3 + 3a^2b + 3ab^2 + b^3\\) | | 4 | \\(a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4\\) | | 5 | \\(a^5 + 5a^4b + 10a^3b^2 + 10a^2b^3 + 5ab^4 + b^5\\) | 一般に\\(n\\)乗の場合は以下のようになる[^fn1]。 \\[ \text{二項定理: } (a+b)^n = \sum_{k=0}^n \binom{n}{k}a^{n-k}b^k \tag{1} \label{binomial_theorem} \\] この式\eqref{binomial_theorem}より〜 [^fn1]: \\(\binom{n}{k}\\) は \\({}_n\mathrm{C}_k\\) と同じ ## 参考 * [二項定理 - Wikipedia](http://ja.wikipedia.org/wiki/%E4%BA%8C%E9%A0%85%E5%AE%9A%E7%90%86)
Mou
- Mou - Markdown editor for web developers, on Mac OS X
- 参考情報:全部無料で。EvernoteにMarkdownで書いたCSS対応の文書を投稿するやり方- 三等兵(2012-06-02)
Preferences で Enable Math にチェックを入れると、TeXをインストールしていない環境でもMathJaxを利用して数式等をきれいに表示できる。
AppleScript
- Markdown から XHTML を生成する(テキストエディットの最前面の文書を処理)
Perl で書かれた Markdown.pl(Daring Fireball: Markdown からダウンロードできる)を利用します。Markdown.pl は好きなところに置いていいですが、ここでは /Applications/Markdown_1.0.1/ のフォルダ内に置かれていると仮定しています。
tell application "TextEdit" activate if not (exists front document) then return if not (exists path of front document) then display dialog "文書を標準テキストで保存してから実行して下さい" buttons {"OK"} giving up after 5 default button 1 return end if set thePath to path of front document -- 最前面の文書のパス set perlCode to quoted form of "/Applications/Markdown_1.0.1/Markdown.pl" -- Markdown.pl を /Applications/Markdown_1.0.1/ に置いた場合 -- set perlCode to quoted form of (POSIX path of (path to applications folder) & "Markdown_1.0.1/Markdown.pl") set newText to do shell script "perl " & perlCode & space & quoted form of thePath set newDoc to make new document -- 新規文書として作成する場合 -- set newDoc to front document -- 元の文書と置き換える場合 set text of newDoc to newText end tell
- Mail.app で選択しているメッセージを Marked で開く
メールが Markdown の形式で書かれていれば便利かもしれません
tell application "Mail" activate set selectedMessages to selection if (count items of selectedMessages) = 0 then display dialog "メッセージを選択してから実行してください" buttons {"OK"} giving up after 5 default button 1 end if -- 選択されたメッセージを temporary items フォルダに保存する repeat with aMessage in selectedMessages set messageText to (content of aMessage) as string set tmpName to "Mail_" & message id of aMessage & ".txt" set tmpFile to ((path to temporary items from user domain) as string) & tmpName open for access file tmpFile with write permission write messageText to file tmpFile as «class utf8» close access file tmpFile tell application "Marked 2" activate open tmpFile as alias end tell end repeat end tell
- MacJournal で選択しているエントリー(標準テキスト)を Marked で開く
tell application "MacJournal" activate -- set selectedEntries to selected entries set selectedEntries to a reference to selected entries as list if (count items of selectedEntries) = 0 then display dialog "標準テキストのエントリーを選択してから実行してください" buttons {"OK"} giving up after 5 default button 1 end if repeat with anEntry in selectedEntries repeat 1 times set entryPath to content file of anEntry tell application "System Events" to set entryInfo to properties of (entryPath as alias) if kind of entryInfo is not in {"テキスト", "標準テキスト書類", "標準テキスト"} then exit repeat tell application "Marked 2" activate open entryPath as alias end tell end repeat end repeat end tell
- 文書の最初の部分にあるメタデータを変更する(テキストエディットの最前面の文書を処理)
文書の最初の部分にあるTitle等の「データ名: データ」という形式を探して見つけたら変更します。ここでは Timestamp: 2015-09-19 01:23:45 +0900 のような形式のタイムスタンプを現在の日時に変更します。
set newData to "Timestamp: " & (do shell script "date '+%F %T %z'") & return tell front document of application "TextEdit" -- ここを変えるだけで Jedit X でもそのまま動作する set idx to 1 repeat while paragraph idx contains ":" if paragraph idx begins with "Timestamp:" then set theInfo to properties of first character of paragraph idx -- 古いデータを新しいデータで置換する場合 make paragraph at paragraph idx with data newData with properties {font:font of theInfo, color:color of theInfo, size:size of theInfo} (* -- 古いデータを頭に old をつけて残す場合 make new paragraph at beginning of paragraph idx with data "old " with properties {font:font of theInfo, color:color of theInfo, size:size of theInfo} make new paragraph at end of paragraph idx with data newData with properties {font:font of theInfo, color:color of theInfo, size:size of theInfo} *) -- save return end if set idx to idx + 1 end repeat display dialog "文書の先頭部分に変更するデータが見つかりませんでした" buttons {"OK"} giving up after 5 default button 1 end tell
set newData to "Timestamp: " & (do shell script "date '+%F %T %z'") & return tell front document of application "TextEdit" -- ここを変えるだけで Jedit X でもそのまま動作する if exists (first paragraph where it begins with "Timestamp:") then set oldData to a reference to (first paragraph where it begins with "Timestamp:") set theInfo to properties of first character of oldData -- 古いデータを新しいデータで置換する場合 make paragraph at oldData with data newData with properties {font:font of theInfo, color:color of theInfo, size:size of theInfo} (* -- 古いデータを頭に old をつけて残す場合 make new paragraph at end of oldData with data newData with properties {font:font of theInfo, color:color of theInfo, size:size of theInfo} make new paragraph at beginning of oldData with data "old " with properties {font:font of theInfo, color:color of theInfo, size:size of theInfo} *) -- save else display dialog "文書に変更するデータが見つかりませんでした" buttons {"OK"} giving up after 5 default button 1 end if end tell