fork(106) download
  1. import sys
  2. import re
  3.  
  4. # on Python 3.5
  5.  
  6. '''
  7. v0.7 Aug. 02, 2018
  8. - conv_sublist() avoids converting C++ comment (e.g. //---)
  9. v0.6 Jun. 22, 2018
  10. - conv_super_pre_notation() handles [vhdl]
  11. - conv_super_pre_notation() handles [verilog]
  12. v0.5 May, 29, 2018
  13. - add conv_tex()
  14. v0.4 Apr. 25, 2018
  15. - add conv_tableFormat()
  16. v0.3 Apr. 25, 2018
  17. - conv_super_pre_notation() takes cpp notation
  18. v0.2 Apr. 25, 2018
  19. - add conv_super_pre_notation()
  20. - add conv_sublist()
  21. v0.1 Apr. 24, 2018
  22. - sub list is converted to Markdown style
  23. '''
  24.  
  25.  
  26. def conv_tex(intxt):
  27. if r"[Tex:" in intxt or r"[tex:" in intxt:
  28. wrk = re.sub('\[Tex:', r'```math\r\n', intxt)
  29. wrk = re.sub('\[tex:', r'```math\r\n', wrk)
  30. wrk = re.sub(r']', r'\r\n```', wrk)
  31. return wrk
  32. return intxt
  33.  
  34.  
  35. def conv_sublist(astr):
  36. if "//-" in astr: # C++ comment
  37. return astr
  38. if "---" in astr:
  39. astr = astr.replace("---", SPACE4 + SPACE4 + "-")
  40. if "--" in astr:
  41. astr = astr.replace("--", SPACE4 + "-")
  42. return astr
  43.  
  44.  
  45. def conv_super_pre_notation(astr):
  46. astr = astr.replace(">||", "```")
  47. astr = astr.replace(">|cpp|", "```cpp")
  48. astr = astr.replace(">|c|", "```c")
  49. astr = astr.replace("||<", "```")
  50. astr = astr.replace(">|verilog|", "```verilog")
  51. astr = astr.replace(">|vhdl|", "```vhdl")
  52. return astr
  53.  
  54.  
  55. def getTableFormat(numVertical):
  56. wrk = "|"
  57. for loop in range(numVertical - 1): # -1: except for first
  58. wrk += ":-:|"
  59. return wrk
  60.  
  61.  
  62. def conv_tableFormat(astr):
  63. global countTbl
  64. if "|" in astr:
  65. countTbl += 1
  66. if countTbl == 2:
  67. num = astr.count('|')
  68. fmt = getTableFormat(num)
  69. return fmt + "\r\n" + astr
  70. else:
  71. countTbl = 0
  72. return astr
  73.  
  74. # read from stdin
  75. lines = sys.stdin.readlines()
  76.  
  77. SPACE4 = " "
  78.  
  79. countTbl = 0 # Table format counter
  80. for elem in lines:
  81. wrk = conv_sublist(elem)
  82. wrk = conv_super_pre_notation(wrk)
  83. wrk = conv_tableFormat(wrk)
  84. wrk = conv_tex(wrk)
  85. print(wrk, end='')
  86.  
Success #stdin #stdout 0.04s 9536KB
stdin
http://w...content-available-to-author-only...e.jp/weblog/?p=3804

>|cpp|
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:
	TButton *Button1;
	void __fastcall Button1Click(TObject *Sender);
private:
	int testCalc(int val);
public:
	__fastcall TForm1(TComponent* Owner);
};

class TBaz {
public:
	TBaz() : FOnFunc(NULL) {}
	typedef int (__closure *PointerToAFunction)(int);
	__property PointerToAFunction OnFunc = { read=FOnFunc, write=FOnFunc };
	int Func(int Arg) {
		if (FOnFunc) {
			return FOnFunc(Arg);
		}
		return 0;
	}
private:
	PointerToAFunction FOnFunc;
};

//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
||<


>|cpp|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	TBaz tbaz;

	tbaz.OnFunc = testCalc;

	tbaz.Func(20);

}
//---------------------------------------------------------------------------
int TForm1::testCalc(int val)
{
	ShowMessage(IntToStr(val));
}
//---------------------------------------------------------------------------
||<
stdout
http://w...content-available-to-author-only...e.jp/weblog/?p=3804

```cpp
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:
	TButton *Button1;
	void __fastcall Button1Click(TObject *Sender);
private:
	int testCalc(int val);
public:
	__fastcall TForm1(TComponent* Owner);
};

class TBaz {
public:
	TBaz() : FOnFunc(NULL) {}
	typedef int (__closure *PointerToAFunction)(int);
	__property PointerToAFunction OnFunc = { read=FOnFunc, write=FOnFunc };
	int Func(int Arg) {
		if (FOnFunc) {
			return FOnFunc(Arg);
		}
		return 0;
	}
private:
	PointerToAFunction FOnFunc;
};

//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
```


```cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	TBaz tbaz;

	tbaz.OnFunc = testCalc;

	tbaz.Func(20);

}
//---------------------------------------------------------------------------
int TForm1::testCalc(int val)
{
	ShowMessage(IntToStr(val));
}
//---------------------------------------------------------------------------
```