Różnice między wybraną wersją a wersją aktualną.
Poprzednia rewizja po obu stronachPoprzednia wersjaNowa wersja | Poprzednia wersja | ||
narzedzia:pandoc_wrapper [2025/05/07 19:05] – administrator | narzedzia:pandoc_wrapper [2025/05/16 18:45] (aktualna) – administrator | ||
---|---|---|---|
Linia 1: | Linia 1: | ||
- | skrypt do pobrania: | + | {{ :narzedzia: |
- | {{ : | + | ====== |
- | + | ||
- | {{ : | + | |
- | + | ||
- | ====== Pandoc Converter GUI ====== | + | |
Skrypt jest aplikacją PowerShell, która wykorzystuje Windows Forms w celu stworzenia graficznego interfejsu użytkownika (GUI) umożliwiającego konwersję plików z jednego formatu na inny za pomocą narzędzia Pandoc. W skrócie, skrypt umożliwia użytkownikowi wybór pliku wejściowego, | Skrypt jest aplikacją PowerShell, która wykorzystuje Windows Forms w celu stworzenia graficznego interfejsu użytkownika (GUI) umożliwiającego konwersję plików z jednego formatu na inny za pomocą narzędzia Pandoc. W skrócie, skrypt umożliwia użytkownikowi wybór pliku wejściowego, | ||
Linia 54: | Linia 50: | ||
===== Podsumowanie ===== | ===== Podsumowanie ===== | ||
Skrypt zapewnia łatwy sposób konwertowania plików między wieloma formatami, oferując użytkownikowi prosty interfejs graficzny do wyboru plików i formatów. Obsługuje różnorodne formaty wejściowe i wyjściowe obsługiwane przez Pandoc oraz zapewnia walidację danych i obsługę błędów. | Skrypt zapewnia łatwy sposób konwertowania plików między wieloma formatami, oferując użytkownikowi prosty interfejs graficzny do wyboru plików i formatów. Obsługuje różnorodne formaty wejściowe i wyjściowe obsługiwane przez Pandoc oraz zapewnia walidację danych i obsługę błędów. | ||
+ | |||
+ | kod skryptu: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <code powershell pandoc.ps1> | ||
+ | # Ensure necessary assemblies are loaded | ||
+ | Add-Type -AssemblyName System.Windows.Forms | ||
+ | Add-Type -AssemblyName System.Drawing | ||
+ | |||
+ | # Comprehensive list of Pandoc-supported input formats | ||
+ | $availableInputFormats = @( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | |||
+ | # Comprehensive list of Pandoc-supported output formats | ||
+ | $availableOutputFormats = @( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | |||
+ | # Create the main form | ||
+ | $form = New-Object System.Windows.Forms.Form | ||
+ | $form.Text = " | ||
+ | $form.Size = New-Object System.Drawing.Size(600, | ||
+ | $form.StartPosition = " | ||
+ | |||
+ | # --- Input File Controls --- | ||
+ | $inputLabel = New-Object System.Windows.Forms.Label | ||
+ | $inputLabel.Location = New-Object System.Drawing.Point(10, | ||
+ | $inputLabel.Size = New-Object System.Drawing.Size(100, | ||
+ | $inputLabel.Text = "Input File:" | ||
+ | $form.Controls.Add($inputLabel) | ||
+ | |||
+ | $inputTextBox = New-Object System.Windows.Forms.TextBox | ||
+ | $inputTextBox.Location = New-Object System.Drawing.Point(120, | ||
+ | $inputTextBox.Size = New-Object System.Drawing.Size(350, | ||
+ | $form.Controls.Add($inputTextBox) | ||
+ | |||
+ | $inputBrowseButton = New-Object System.Windows.Forms.Button | ||
+ | $inputBrowseButton.Location = New-Object System.Drawing.Point(480, | ||
+ | $inputBrowseButton.Size = New-Object System.Drawing.Size(80, | ||
+ | $inputBrowseButton.Text = " | ||
+ | $inputBrowseButton.Add_Click({ | ||
+ | $openDialog = New-Object System.Windows.Forms.OpenFileDialog | ||
+ | $openDialog.Filter = "All Files (*.*)|*.*" | ||
+ | $openDialog.Title = " | ||
+ | if ($openDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]:: | ||
+ | $inputTextBox.Text = $openDialog.FileName | ||
+ | } | ||
+ | }) | ||
+ | $form.Controls.Add($inputBrowseButton) | ||
+ | |||
+ | # --- Output File Controls --- | ||
+ | $outputLabel = New-Object System.Windows.Forms.Label | ||
+ | $outputLabel.Location = New-Object System.Drawing.Point(10, | ||
+ | $outputLabel.Size = New-Object System.Drawing.Size(100, | ||
+ | $outputLabel.Text = " | ||
+ | $form.Controls.Add($outputLabel) | ||
+ | |||
+ | $outputTextBox = New-Object System.Windows.Forms.TextBox | ||
+ | $outputTextBox.Location = New-Object System.Drawing.Point(120, | ||
+ | $outputTextBox.Size = New-Object System.Drawing.Size(350, | ||
+ | $form.Controls.Add($outputTextBox) | ||
+ | |||
+ | $outputBrowseButton = New-Object System.Windows.Forms.Button | ||
+ | $outputBrowseButton.Location = New-Object System.Drawing.Point(480, | ||
+ | $outputBrowseButton.Size = New-Object System.Drawing.Size(80, | ||
+ | $outputBrowseButton.Text = " | ||
+ | $outputBrowseButton.Add_Click({ | ||
+ | $saveDialog = New-Object System.Windows.Forms.SaveFileDialog | ||
+ | $saveDialog.Filter = "All Files (*.*)|*.*" | ||
+ | $saveDialog.Title = " | ||
+ | if ($saveDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]:: | ||
+ | $outputTextBox.Text = $saveDialog.FileName | ||
+ | } | ||
+ | }) | ||
+ | $form.Controls.Add($outputBrowseButton) | ||
+ | |||
+ | # --- Input Format ComboBox --- | ||
+ | $inputFormatLabel = New-Object System.Windows.Forms.Label | ||
+ | $inputFormatLabel.Location = New-Object System.Drawing.Point(10, | ||
+ | $inputFormatLabel.Size = New-Object System.Drawing.Size(100, | ||
+ | $inputFormatLabel.Text = "Input Format:" | ||
+ | $form.Controls.Add($inputFormatLabel) | ||
+ | |||
+ | $inputFormatCombo = New-Object System.Windows.Forms.ComboBox | ||
+ | $inputFormatCombo.Location = New-Object System.Drawing.Point(120, | ||
+ | $inputFormatCombo.Size = New-Object System.Drawing.Size(200, | ||
+ | $inputFormatCombo.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]:: | ||
+ | foreach ($fmt in $availableInputFormats) { | ||
+ | $inputFormatCombo.Items.Add($fmt) | Out-Null | ||
+ | } | ||
+ | $inputFormatCombo.SelectedIndex = 0 | ||
+ | $form.Controls.Add($inputFormatCombo) | ||
+ | |||
+ | # --- Output Format ComboBox --- | ||
+ | $outputFormatLabel = New-Object System.Windows.Forms.Label | ||
+ | $outputFormatLabel.Location = New-Object System.Drawing.Point(10, | ||
+ | $outputFormatLabel.Size = New-Object System.Drawing.Size(100, | ||
+ | $outputFormatLabel.Text = " | ||
+ | $form.Controls.Add($outputFormatLabel) | ||
+ | |||
+ | $outputFormatCombo = New-Object System.Windows.Forms.ComboBox | ||
+ | $outputFormatCombo.Location = New-Object System.Drawing.Point(120, | ||
+ | $outputFormatCombo.Size = New-Object System.Drawing.Size(200, | ||
+ | $outputFormatCombo.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]:: | ||
+ | foreach ($fmt in $availableOutputFormats) { | ||
+ | $outputFormatCombo.Items.Add($fmt) | Out-Null | ||
+ | } | ||
+ | $outputFormatCombo.SelectedIndex = 0 | ||
+ | $form.Controls.Add($outputFormatCombo) | ||
+ | |||
+ | # --- Convert and Cancel Buttons --- | ||
+ | $convertButton = New-Object System.Windows.Forms.Button | ||
+ | $convertButton.Location = New-Object System.Drawing.Point(250, | ||
+ | $convertButton.Size = New-Object System.Drawing.Size(80, | ||
+ | $convertButton.Text = " | ||
+ | $convertButton.DialogResult = [System.Windows.Forms.DialogResult]:: | ||
+ | $form.Controls.Add($convertButton) | ||
+ | |||
+ | $cancelButton = New-Object System.Windows.Forms.Button | ||
+ | $cancelButton.Location = New-Object System.Drawing.Point(350, | ||
+ | $cancelButton.Size = New-Object System.Drawing.Size(80, | ||
+ | $cancelButton.Text = " | ||
+ | $cancelButton.DialogResult = [System.Windows.Forms.DialogResult]:: | ||
+ | $form.Controls.Add($cancelButton) | ||
+ | |||
+ | $form.AcceptButton = $convertButton | ||
+ | $form.CancelButton = $cancelButton | ||
+ | |||
+ | # Show the form and wait for user interaction | ||
+ | $result = $form.ShowDialog() | ||
+ | |||
+ | if ($result -eq [System.Windows.Forms.DialogResult]:: | ||
+ | $inputFile = $inputTextBox.Text | ||
+ | $outputFile = $outputTextBox.Text | ||
+ | $selectedInputFormat = $inputFormatCombo.SelectedItem | ||
+ | $selectedOutputFormat = $outputFormatCombo.SelectedItem | ||
+ | |||
+ | # Validate file selections | ||
+ | if ([string]:: | ||
+ | [System.Windows.Forms.MessageBox]:: | ||
+ | [System.Windows.Forms.MessageBoxButtons]:: | ||
+ | [System.Windows.Forms.MessageBoxIcon]:: | ||
+ | exit | ||
+ | } | ||
+ | if ([string]:: | ||
+ | [System.Windows.Forms.MessageBox]:: | ||
+ | [System.Windows.Forms.MessageBoxButtons]:: | ||
+ | [System.Windows.Forms.MessageBoxIcon]:: | ||
+ | exit | ||
+ | } | ||
+ | |||
+ | # If input file has .tex extension and user selected ' | ||
+ | $ext = [System.IO.Path]:: | ||
+ | if ($ext -eq " | ||
+ | [System.Windows.Forms.MessageBox]:: | ||
+ | " | ||
+ | [System.Windows.Forms.MessageBoxIcon]:: | ||
+ | $selectedInputFormat = " | ||
+ | } | ||
+ | |||
+ | # Check if pandoc is available | ||
+ | if (-not (Get-Command pandoc -ErrorAction SilentlyContinue)) { | ||
+ | [System.Windows.Forms.MessageBox]:: | ||
+ | " | ||
+ | [System.Windows.Forms.MessageBoxIcon]:: | ||
+ | exit | ||
+ | } | ||
+ | |||
+ | # Run pandoc conversion using selected formats (-f for input, -t for output) | ||
+ | pandoc " | ||
+ | |||
+ | [System.Windows.Forms.MessageBox]:: | ||
+ | " | ||
+ | [System.Windows.Forms.MessageBoxIcon]:: | ||
+ | } else { | ||
+ | Write-Host " | ||
+ | } | ||
+ | |||
+ | </ | ||