Last active
August 3, 2017 02:31
-
-
Save jkingsman/ad7f84ddb0baa54377f075a10ae5e851 to your computer and use it in GitHub Desktop.
ETH Markdown Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60606040525b60008054600160a060020a03191633600160a060020a03161790555b5b610a7b806100316000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166320fba162811461005357806341c0e1b5146100de57806366792ba1146100f3575b600080fd5b341561005e57600080fd5b6100666101bc565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100a35780820151818401525b60200161008a565b50505050905090810190601f1680156100d05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156100e957600080fd5b6100f16101e2565b005b34156100fe57600080fd5b61006660046024813581810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965061022495505050505050565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100a35780820151818401525b60200161008a565b50505050905090810190601f1680156100d05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101c46109a3565b60c060405190810160405260888082526109c8602083013990505b90565b6000543373ffffffffffffffffffffffffffffffffffffffff908116911614156102215760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b61022c6109a3565b6102346109a3565b61023c6109a3565b8391506000808080805b86518110156106e95781156102875761027c8688838151811061026557fe5b016020015160f860020a900460f860020a02610792565b9550600091506106dd565b60408051908101604052600181527f2a0000000000000000000000000000000000000000000000000000000000000060208201526000815181106102c757fe5b016020015160f860020a900460f860020a02600160f860020a0319168782815181106102ef57fe5b016020015160f860020a900460f860020a02600160f860020a03191614156103ba578415156103855761037e86606060405190810160405280602181526020017f3c7370616e207374796c653d22666f6e742d7765696768743a20626f6c643b2281526020017f3e00000000000000000000000000000000000000000000000000000000000000815250610878565b95506103b2565b6103af86604080519081016040526007815260c960020a661e17b9b830b71f026020820152610878565b95505b9315936106dd565b60408051908101604052600181527f5f0000000000000000000000000000000000000000000000000000000000000060208201526000815181106103fa57fe5b016020015160f860020a900460f860020a02600160f860020a03191687828151811061042257fe5b016020015160f860020a900460f860020a02600160f860020a03191614156104ed578315156104b8576104b186606060405190810160405280602a81526020017f3c7370616e207374796c653d22746578742d6465636f726174696f6e3a20756e81526020017f6465726c696e653b223e00000000000000000000000000000000000000000000815250610878565b95506104e5565b6104e286604080519081016040526007815260c960020a661e17b9b830b71f026020820152610878565b95505b9215926106dd565b60408051908101604052600181527f2f00000000000000000000000000000000000000000000000000000000000000602082015260008151811061052d57fe5b016020015160f860020a900460f860020a02600160f860020a03191687828151811061055557fe5b016020015160f860020a900460f860020a02600160f860020a0319161415610620578215156105eb576105e486606060405190810160405280602281526020017f3c7370616e207374796c653d22666f6e742d7374796c653a206974616c69633b81526020017f223e000000000000000000000000000000000000000000000000000000000000815250610878565b9550610618565b61061586604080519081016040526007815260c960020a661e17b9b830b71f026020820152610878565b95505b9115916106dd565b60408051908101604052600181527f5c00000000000000000000000000000000000000000000000000000000000000602082015260008151811061066057fe5b016020015160f860020a900460f860020a02600160f860020a03191687828151811061068857fe5b016020015160f860020a900460f860020a02600160f860020a03191614156106b357600191506106dd565b6106da8688838151811061026557fe5b016020015160f860020a900460f860020a02610792565b95505b5b5b5b5b600101610246565b841561071c5761071986604080519081016040526007815260c960020a661e17b9b830b71f026020820152610878565b95505b831561074f5761074c86604080519081016040526007815260c960020a661e17b9b830b71f026020820152610878565b95505b82156107825761077f86604080519081016040526007815260c960020a661e17b9b830b71f026020820152610878565b95505b8597505b50505050505050919050565b61079a6109a3565b6107a26109a3565b6107aa6109a3565b6107b26109a3565b60008087945084516001016040518059106107ca5750595b908082528060200260200182016040525b50935083925060009150600090505b8451811015610844578481815181106107ff57fe5b016020015160f860020a900460f860020a0283838060010194508151811061082357fe5b906020010190600160f860020a031916908160001a9053505b6001016107ea565b8683838151811061085157fe5b906020010190600160f860020a031916908160001a9053508295505b505050505092915050565b6108806109a3565b6108886109a3565b6108906109a3565b6108986109a3565b6108a06109a3565b60008088955087945084518651016040518059106108bb5750595b908082528060200260200182016040525b50935083925060009150600090505b8551811015610935578581815181106108f057fe5b016020015160f860020a900460f860020a0283838060010194508151811061091457fe5b906020010190600160f860020a031916908160001a9053505b6001016108db565b5060005b84518110156109935784818151811061094e57fe5b016020015160f860020a900460f860020a0283838060010194508151811061097257fe5b906020010190600160f860020a031916908160001a9053505b600101610939565b8296505b50505050505092915050565b60206040519081016040526000815290565b6020604051908101604052600081529056005468697320697320612073696d706c65206d61726b646f776e2d3e48544d4c20636f6e7665727465722028652e672e202a626f6c642a2c205f756e6465726c696e655f2c202f6974616c6963732f292e20557365206261636b736c61736820746f20666f726365206c69746572616c20636861722028652e672e205c2a617374657269736b5c2a29a165627a7a7230582043c2ebd0317fbddd18f56f79d3e143adcfe9cbccb5fd556c5fd32aa7a647504300296060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b60bb8061003b6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166341c0e1b58114603c575b600080fd5b3415604657600080fd5b604c604e565b005b6000543373ffffffffffffffffffffffffffffffffffffffff90811691161415608c5760005473ffffffffffffffffffffffffffffffffffffffff16ff5b5b5600a165627a7a72305820a834075564d172470f9909bd065ae3196875ae4714c35b02208663470832a1230029 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract mortal { | |
/* Define variable owner of the type address*/ | |
address owner; | |
/* this function is executed at initialization and sets the owner of the contract */ | |
function mortal() { owner = msg.sender; } | |
/* Function to recover the funds on the contract */ | |
function kill() { if (msg.sender == owner) selfdestruct(owner); } | |
} | |
contract markdownConvert is mortal { | |
// concatenate two strings | |
function concat(string _a, string _b) internal returns (string){ | |
bytes memory _ba = bytes(_a); | |
bytes memory _bb = bytes(_b); | |
string memory ab = new string(_ba.length + _bb.length); | |
bytes memory bab = bytes(ab); | |
uint k = 0; | |
for (uint i = 0; i < _ba.length; i++) bab[k++] = _ba[i]; | |
for (i = 0; i < _bb.length; i++) bab[k++] = _bb[i]; | |
return string(bab); | |
} | |
// concatenate a byte to a string | |
function concatByte(string _a, byte _b) internal returns (string){ | |
bytes memory aBytes = bytes(_a); | |
string memory expandedA = new string(aBytes.length + 1); | |
bytes memory finalBytes = bytes(expandedA); | |
uint k = 0; | |
for (uint i = 0; i < aBytes.length; i++) finalBytes[k++] = aBytes[i]; | |
finalBytes[k] = _b; | |
return string(finalBytes); | |
} | |
// const definitions | |
string constant boldSpan = '<span style="font-weight: bold;">'; | |
string constant underlineSpan = '<span style="text-decoration: underline;">'; | |
string constant italicSpan = '<span style="font-style: italic;">'; | |
string constant spanClose = '</span>'; | |
string constant asteriskStr = '*'; | |
string constant underscoreStr = '_'; | |
string constant forwardslashStr = '/'; | |
string constant backslashStr = '\\'; | |
byte constant asterisk = bytes(asteriskStr)[0]; | |
byte constant underscore = bytes(underscoreStr)[0]; | |
byte constant forwardslash = bytes(forwardslashStr)[0]; | |
byte constant backslash = bytes(backslashStr)[0]; | |
/* main function */ | |
function send(string inString) constant returns (string) { | |
bytes memory inBytes = bytes(inString); | |
string memory returnString; | |
bool openBold = false; // there is currently an open bold tag | |
bool openUnderline = false; // etc. | |
bool openItalic = false; // etc. | |
bool escaped = false; // flag to indicate the last character was a backslash | |
// loop through all bytes of input | |
for (uint i = 0; i < inBytes.length; i++){ | |
if(escaped){ | |
// write the char literally and skip parsing | |
returnString = concatByte(returnString, inBytes[i]); | |
escaped = false; | |
continue; | |
} | |
// scan for format chars | |
if(inBytes[i] == asterisk){ | |
if(!openBold){ | |
// add an opening tag | |
returnString = concat(returnString, boldSpan); | |
} else { | |
// already have one open; close it | |
returnString = concat(returnString, spanClose); | |
} | |
// toggle tag open status whatever we did | |
openBold = !openBold; | |
} else if (inBytes[i] == underscore){ | |
if(!openUnderline){ | |
returnString = concat(returnString, underlineSpan); | |
} else { | |
returnString = concat(returnString, spanClose); | |
} | |
openUnderline = !openUnderline; | |
} else if (inBytes[i] == forwardslash){ | |
if(!openItalic){ | |
returnString = concat(returnString, italicSpan); | |
} else { | |
returnString = concat(returnString, spanClose); | |
} | |
openItalic = !openItalic; | |
} else if (inBytes[i] == backslash){ | |
// the next char is escaed; set flag to print as literal | |
escaped = true; | |
} else { | |
returnString = concatByte(returnString, inBytes[i]); | |
} | |
} | |
// close up remaining tags if something is left open | |
if(openBold){ | |
returnString = concat(returnString, spanClose); | |
} | |
if(openUnderline){ | |
returnString = concat(returnString, spanClose); | |
} | |
if(openItalic){ | |
returnString = concat(returnString, spanClose); | |
} | |
return returnString; | |
} | |
// eth man pages? :D | |
function help() constant returns (string) { | |
return "This is a simple markdown->HTML converter (e.g. *bold*, _underline_, /italics/). Use backslash to force literal char (e.g. \\*asterisk\\*)"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"constant":true,"inputs":[],"name":"help","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"inString","type":"string"}],"name":"send","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment