add function to copy selection table to markdown on clipboard

This commit is contained in:
Paul Trowbridge 2017-08-17 10:00:18 -04:00
parent b311408659
commit aab361bbf3

44
FL.bas
View File

@ -583,3 +583,47 @@ Sub LoadChan()
End Sub End Sub
Sub markdown_from_table()
Dim wapi As New Windows_API
Dim tbl() As Variant
tbl = Selection
Dim msl() As Integer
Dim md As String
Dim r As Integer
Dim c As Integer
ReDim msl(UBound(tbl, 2))
'---determine max string length per column----
For c = 1 To UBound(tbl, 2)
For r = 1 To UBound(tbl, 1)
If Len(tbl(r, c)) > msl(c) Then msl(c) = Len(tbl(r, c))
Next r
Next c
'---build markdown table-----------
For r = 1 To UBound(tbl, 1)
If r = 2 Then
md = md & "|"
For c = 1 To UBound(tbl, 2)
md = md & "---" & String(msl(c) - 3, "-") & "|"
Next c
md = md & vbCrLf
End If
md = md & "|"
For c = 1 To UBound(tbl, 2)
md = md & tbl(r, c) & String(msl(c) - Len(tbl(r, c)), " ") & "|"
Next c
md = md & vbCrLf
Next r
Call wapi.ClipBoard_SetData(md)
End Sub