Jump to content

Search the Community

Showing results for tags 'markdown'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. _ArrayToMdTable Converts an array to a markdown table format | Item | In Stock | Price | | :---------------- | :------: | ----: | | Python Hat | True | 23.99 | | SQL Hat | True | 23.99 | | Codecademy Tee | False | 19.99 | | Codecademy Hoodie | False | 42.99 | @SOLVE-SMART I did it on the occasion of your suggestion. I modified it to better suit the requirements of Markdown, and to be more readable. ; https://www.autoitscript.com/forum/topic/212883-_arraytomdtable ;---------------------------------------------------------------------------------------- ; Title...........: _ArrayToMdTable ; Description.....: Converts an array to a markdown table format. ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 1.0 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <Array.au3> #include <String.au3> Example1() ; Example 2D array to table Example2() ; Example 1D array to table ;--------------------------------------------------------------------------------------- Func Example1() ; Example 2D array to table Local $aData[5][3] = [["Item", "In Stock", "Price"], _ ["Python Hat", "True", "23.99"], _ ["SQL Hat", "True", "23.99"], _ ["Codecademy Tee", "False", "19.99"], _ ["Codecademy Hoodie", "False", "42.99"]] Local $sTable = _ArrayToMdTable($aData, "L,C,R") ConsoleWrite($sTable) EndFunc ;==>Example1 ;--------------------------------------------------------------------------------------- Func Example2() ; Example 1D array to table Local $sMonth = "Months, January, February, March, April, May, June, July, August, September, October, November, December" Local $aMonth = StringSplit($sMonth, ", ", 3) $sMonth = _ArrayToMdTable($aMonth, "C") ConsoleWrite($sMonth) EndFunc ;==>Example2 ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _ArrayToMDtable ; Description....: Converts an array to a Markdown table format. ; Syntax.........: _ArrayToMdTable( $aArray [, $sAlign = "" ] ) ; Parameters.....: $aArray - The array to be converted. ; $sAlign - [optional] Alignment options for each column (e.g., "L,R,C"). (Default is "" (left-aligned)) ; Return values..: The formatted table as a string. ; Author ........: ioa747 ; Notes .........: This function takes a array and converts it into a Markdown table. ; It calculates the width of each column based on the longest string in that column. ; Link ..........: ; Dependencies...: __FormatCell() ;------------------------------------------------------------------------------------------------------------------------------------ Func _ArrayToMdTable($aArray, $sAlign = "") Local $sTable = "" Local $b2D = (UBound($aArray, 0) = 1 ? False : True) ; if $aArray = 1D => force 2D (Insert extra coloumn) If Not $b2D Then _ArrayColInsert($aArray, 1) Local $iRowCount = UBound($aArray, 1) Local $iColCount = UBound($aArray, 2) Local $aColWidths[$iColCount] Local $aAlign[$iColCount] ; get max width For $j = 0 To $iColCount - 1 $aColWidths[$j] = 0 For $i = 0 To $iRowCount - 1 $aColWidths[$j] = $aColWidths[$j] > StringLen($aArray[$i][$j]) ? $aColWidths[$j] : StringLen($aArray[$i][$j]) Next Next ; Alignment initialize If $sAlign <> "" Then Local $aRawAlign = StringSplit($sAlign, ",", 2) Local $iRawCnt = UBound($aRawAlign) For $j = 0 To $iColCount - 1 If $j >= $iRawCnt Then $aAlign[$j] = "L" Else $aAlign[$j] = StringStripWS(StringUpper($aRawAlign[$j]), 3) If Not StringRegExp($aAlign[$j], "^[LRC]$") Then $aAlign[$j] = "L" EndIf Next Else For $j = 0 To $iColCount - 1 $aAlign[$j] = "L" Next EndIf ; Create the header row For $i = 0 To $iColCount - 1 $sTable &= "| " & __FormatCell($aArray[0][$i], $aColWidths[$i], $aAlign[$i]) & " " Next $sTable &= "|" & @CRLF ; Create the alignment row $sTable &= "|" For $i = 0 To $iColCount - 1 Switch $aAlign[$i] Case "L" $sTable &= " :" & _StringRepeat("-", $aColWidths[$i] - 1) & " " Case "R" $sTable &= " " & _StringRepeat("-", $aColWidths[$i] - 1) & ": " Case "C" $sTable &= " :" & _StringRepeat("-", $aColWidths[$i] - 2) & ": " Case Else $sTable &= " " & _StringRepeat("-", $aColWidths[$i]) & " " EndSwitch $sTable &= "|" Next $sTable &= @CRLF ; Create the data rows For $i = 1 To $iRowCount - 1 For $j = 0 To $iColCount - 1 $sTable &= "| " & __FormatCell($aArray[$i][$j], $aColWidths[$j], $aAlign[$j]) & " " Next $sTable &= "|" & @CRLF Next ; remove the extra coloumn If Not $b2D Then $sTable = StringRegExpReplace($sTable, "(\| \||\| : \||\| :: \|)", "|") Return $sTable EndFunc ;==>_ArrayToMdTable ;--------------------------------------------------------------------------------------- Func __FormatCell($text, $width, $align) ; internal Switch $align Case "R" Return StringFormat("%" & $width & "s", $text) Case "C" Local $pad = $width - StringLen($text) Local $left = Floor($pad / 2) Local $right = $pad - $left Return _StringRepeat(" ", $left) & $text & _StringRepeat(" ", $right) Case Else ; "L" Return StringFormat("%-" & $width & "s", $text) EndSwitch EndFunc ;==>__FormatCell ;--------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much
×
×
  • Create New...