Compare commits
No commits in common. "master" and "v0.0.2" have entirely different histories.
@ -1,4 +1,3 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
[assembly: ThemeInfo(
|
[assembly: ThemeInfo(
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<Window x:Name="Txt2BibWindow" x:Class="Txt2Bib.MainWindow"
|
<Window x:Class="Txt2Bib.MainWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:Txt2Bib"
|
xmlns:local="clr-namespace:Txt2Bib"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Txt2Bib" Height="744" Width="800" Icon="/aec_icon.png">
|
Title="MainWindow" Height="744" Width="800">
|
||||||
<Grid Background="#FF38383E" Margin="0,0,0,-16">
|
<Grid Background="#FF38383E" Margin="0,0,0,-6">
|
||||||
<TextBox x:Name="DropArea" Text="Trascinare qui i file txt da convertire" ToolTip="Trascinare qui i file txt da convertire" HorizontalAlignment="Left" Margin="48,105,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="710" Height="245" PreviewDragEnter="DropArea_PreviewDragEnter" PreviewDragOver="DropArea_PreviewDragOver" Drop="DropArea_Drop"/>
|
<TextBox x:Name="DropArea" Text="Trascinare qui i file txt da convertire" ToolTip="Trascinare qui i file txt da convertire" HorizontalAlignment="Left" Margin="48,82,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="526" Height="437" PreviewDragEnter="DropArea_PreviewDragEnter" PreviewDragOver="DropArea_PreviewDragOver" Drop="DropArea_Drop"/>
|
||||||
<TextBox x:Name="Debug" VerticalScrollBarVisibility="Auto" IsEnabled="True" HorizontalAlignment="Left" Margin="48,458,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="710" Height="224" RenderTransformOrigin="0.449,1.525"/>
|
<TextBox x:Name="Debug" VerticalScrollBarVisibility="Auto" IsEnabled="True" HorizontalAlignment="Left" Margin="48,571,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="710" Height="106" RenderTransformOrigin="0.449,1.525"/>
|
||||||
<Label Content="Txt2Bib" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Eras ITC" FontSize="28"/>
|
<Label Content="Txt2Bib" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Eras ITC" FontSize="28"/>
|
||||||
<Button x:Name="GoBtn" Cursor="Hand" Content="Esegui" HorizontalAlignment="Left" Margin="340,367,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="50" Width="126" Click="GoBtn_Click" BorderBrush="{x:Null}" Foreground="White" Background="#FF3F9865" FontFamily="Cascadia Code" FontSize="16">
|
<Button x:Name="GoBtn" Cursor="Hand" Content="Genera" HorizontalAlignment="Left" Margin="631,82,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="68" Width="127" Click="GoBtn_Click" BorderBrush="{x:Null}" Foreground="White" Background="#FF474671" FontFamily="Cascadia Code" FontSize="16">
|
||||||
<Button.RenderTransform>
|
<Button.RenderTransform>
|
||||||
<TransformGroup>
|
<TransformGroup>
|
||||||
<ScaleTransform/>
|
<ScaleTransform/>
|
||||||
@ -20,27 +20,15 @@
|
|||||||
</TransformGroup>
|
</TransformGroup>
|
||||||
</Button.RenderTransform>
|
</Button.RenderTransform>
|
||||||
</Button>
|
</Button>
|
||||||
<Label Content="Preview" HorizontalAlignment="Left" Margin="46,421,0,0" VerticalAlignment="Top" Foreground="White"/>
|
<Label Content="Debug" HorizontalAlignment="Left" Margin="44,544,0,0" VerticalAlignment="Top" Foreground="White"/>
|
||||||
<Button x:Name="CopyDebug" ToolTip="Copia contenuto preview negli appunti" Cursor="Hand" Content="Button" HorizontalAlignment="Left" Margin="110,424,0,0" VerticalAlignment="Top" Foreground="{x:Null}" BorderBrush="{x:Null}" Width="26" Background="White" Click="CopyDebug_Click" RenderTransformOrigin="0.554,-4.344" Height="23">
|
<Button x:Name="CopyDebug" Content="Button" HorizontalAlignment="Left" Margin="111,547,0,0" VerticalAlignment="Top" Foreground="{x:Null}" BorderBrush="{x:Null}" Width="23" Background="White" Click="CopyDebug_Click">
|
||||||
<Button.OpacityMask>
|
<Button.OpacityMask>
|
||||||
<ImageBrush Stretch="Uniform" ImageSource="/copy-icon.png"/>
|
<ImageBrush ImageSource="/copy-icon.png"/>
|
||||||
</Button.OpacityMask>
|
</Button.OpacityMask>
|
||||||
</Button>
|
</Button>
|
||||||
<Menu x:Name="FileMenu" Margin="22,53,561,497" Background="#FF4B4E5D" MouseLeave="FileMenu_LostMouseFocus" Visibility="Collapsed">
|
<Button x:Name="OpenDestFolderBtn" ToolTip="Apri cartella destinazione" Content="Button" HorizontalAlignment="Left" Margin="631,168,0,0" VerticalAlignment="Top" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="26" Width="27" Cursor="Hand" Click="OpenDestFolderBtn_Click">
|
||||||
<Menu.ItemsPanel>
|
|
||||||
<ItemsPanelTemplate>
|
|
||||||
<VirtualizingStackPanel Orientation="Vertical"/>
|
|
||||||
</ItemsPanelTemplate>
|
|
||||||
</Menu.ItemsPanel>
|
|
||||||
<Label x:Name="OpenOutputDir" Content="Apri cartella output..." Foreground="White" FontSize="14" MouseDown="OpenOutputDir_MouseDown" Cursor="Hand" Width="160" HorizontalAlignment="Center" Margin="0,6,0,0" >
|
|
||||||
</Label>
|
|
||||||
<Label x:Name="Help" Content="Help" Foreground="White" FontSize="14" MouseDown="Help_MouseDown" Cursor="Hand" Width="161" Margin="0,6,0,0"/>
|
|
||||||
<Label x:Name="About" Content="About" Foreground="White" FontSize="14" MouseDown="About_MouseDown" Cursor="Hand" Width="161" Margin="0,6,0,0"/>
|
|
||||||
<Label x:Name="Exit" Content="Esci..." Foreground="White" FontSize="14" MouseDown="Exit_MouseDown" Cursor="Hand" Width="163" Margin="0,6,0,0"/>
|
|
||||||
</Menu>
|
|
||||||
<Button x:Name="ToggleMenu" Content="" HorizontalAlignment="Left" Margin="12,14,0,0" VerticalAlignment="Top" RenderTransformOrigin="0,0.202" Height="42" Width="47" BorderBrush="{x:Null}" Foreground="{x:Null}" Cursor="Hand" Click="ToggleMenu_Click">
|
|
||||||
<Button.OpacityMask>
|
<Button.OpacityMask>
|
||||||
<ImageBrush ImageSource="/menu-1768000-1502336.png" Stretch="Uniform"/>
|
<ImageBrush ImageSource="/openfolder_4896.png" Stretch="Uniform"/>
|
||||||
</Button.OpacityMask>
|
</Button.OpacityMask>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@ -17,27 +16,7 @@ namespace Txt2Bib
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
OutputDir = $@"{Directory.GetCurrentDirectory()}\bibtex";
|
|
||||||
Directory.CreateDirectory(OutputDir);
|
|
||||||
DropArea.AllowDrop = true;
|
DropArea.AllowDrop = true;
|
||||||
InitialDropText = DropArea.Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string OutputDir { get; }
|
|
||||||
private string InitialDropText { get; }
|
|
||||||
|
|
||||||
private void Execute()
|
|
||||||
{
|
|
||||||
if (DropArea.Text == InitialDropText)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Nessun percorso disponibile...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var txt2bib = new Text2Bib();
|
|
||||||
var result = txt2bib.Generate(DropArea.Text);
|
|
||||||
Debug.Text = result;
|
|
||||||
using var outputFile = new StreamWriter($@"{OutputDir}\output_bibtex.bib");
|
|
||||||
outputFile.Write(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DropArea_Drop(object sender, DragEventArgs e)
|
private void DropArea_Drop(object sender, DragEventArgs e)
|
||||||
@ -55,17 +34,17 @@ namespace Txt2Bib
|
|||||||
if (dataObject.ContainsFileDropList())
|
if (dataObject.ContainsFileDropList())
|
||||||
{
|
{
|
||||||
// Clear values
|
// Clear values
|
||||||
if (DropArea.Text == InitialDropText) DropArea.Text = string.Empty;
|
DropArea.Text = string.Empty;
|
||||||
|
|
||||||
// Process file names
|
// Process file names
|
||||||
var fileNames = dataObject.GetFileDropList();
|
var fileNames = dataObject.GetFileDropList();
|
||||||
var bd = new StringBuilder();
|
StringBuilder bd = new StringBuilder();
|
||||||
foreach (var fileName in fileNames)
|
foreach (var fileName in fileNames)
|
||||||
{
|
{
|
||||||
bd.Append(fileName + "\n");
|
bd.Append(fileName + "\n");
|
||||||
}
|
}
|
||||||
// Set text
|
// Set text
|
||||||
DropArea.Text += bd.ToString();
|
DropArea.Text = bd.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,16 +67,11 @@ namespace Txt2Bib
|
|||||||
|
|
||||||
private void GoBtn_Click(object sender, RoutedEventArgs e)
|
private void GoBtn_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
var txt2bib = new Text2Bib();
|
||||||
{
|
var result = txt2bib.Generate(DropArea.Text);
|
||||||
Execute();
|
Debug.Text = result;
|
||||||
}
|
using var outputFile = new StreamWriter("output_bibtex.bib");
|
||||||
catch (Exception ex)
|
outputFile.Write(result);
|
||||||
{
|
|
||||||
MessageBox.Show($"Errore di esecuzione: {ex.Message}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MessageBox.Show("File BibTeX generato correttamente.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyDebug_Click(object sender, RoutedEventArgs e)
|
private void CopyDebug_Click(object sender, RoutedEventArgs e)
|
||||||
@ -108,47 +82,7 @@ namespace Txt2Bib
|
|||||||
|
|
||||||
private void OpenDestFolderBtn_Click(object sender, RoutedEventArgs e)
|
private void OpenDestFolderBtn_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Process.Start("explorer.exe", OutputDir);
|
System.Diagnostics.Process.Start("explorer.exe", Directory.GetCurrentDirectory());
|
||||||
}
|
|
||||||
|
|
||||||
private void ToggleMenu_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
if (FileMenu.Visibility == Visibility.Collapsed)
|
|
||||||
{
|
|
||||||
FileMenu.Visibility = Visibility.Visible;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FileMenu.Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OpenOutputDir_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
System.Diagnostics.Process.Start("explorer.exe", OutputDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Exit_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Help_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Trascinare i file txt da elaborare nella casella in alto e premere 'Esegui'.\n" +
|
|
||||||
"Il file BibTeX viene generato in una cartella dedicata, che si può aprire selezionando " +
|
|
||||||
"'Apri cartella output' dal menu.", "Help", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FileMenu_LostMouseFocus(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
FileMenu.Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void About_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Txt2Bib version {Assembly.GetExecutingAssembly().GetName().Version}\n" +
|
|
||||||
"Powered by Nicopa", "About", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
244
Records.cs
244
Records.cs
@ -1,272 +1,86 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Txt2Bib.Records
|
namespace Txt2Bib.Records
|
||||||
{
|
{
|
||||||
public interface IBib {
|
public interface IBib { public string ToString(); }
|
||||||
public string Convert(string[] entryLines);
|
|
||||||
public string ToString();
|
|
||||||
};
|
|
||||||
|
|
||||||
public abstract record ItemType
|
public record class ArticleBib : IBib
|
||||||
{
|
|
||||||
public string Pages { get; set; } = "";
|
|
||||||
|
|
||||||
protected static bool IsDoi(string url)
|
|
||||||
{
|
|
||||||
return url.Contains("doi");
|
|
||||||
}
|
|
||||||
protected static string Rearrange(string a)
|
|
||||||
{
|
|
||||||
a = a.Trim();
|
|
||||||
var s = a.Split(' ');
|
|
||||||
return s.Length > 1 ?
|
|
||||||
$"{s[1]} {s[0][0]}{s[0][1..].ToLower()}" : a;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected string CreatePages(string pages)
|
|
||||||
{
|
|
||||||
if (pages.Length == 0) { return ""; }
|
|
||||||
|
|
||||||
return pages.Split('-').Length == 2 ?
|
|
||||||
$"{pages.Split('-')[0]}--{pages.Split('-')[1].TrimEnd('.')}" :
|
|
||||||
pages;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record class Article : ItemType, IBib
|
|
||||||
{
|
{
|
||||||
public string Type { get; init; } = "article";
|
public string Type { get; init; } = "article";
|
||||||
public string[] Author { get; set; } = { "Gianni e Pinotto" };
|
public string[] Author { get; set; } = { "Gianni e Pinotto" };
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
public string Journal { get; set; } = "";
|
public string Journal { get; set; } = "";
|
||||||
public ushort Year { get; set; } = 1950;
|
public ushort Year { get; set; } = 1950;
|
||||||
public string Volume { get; set; } = "";
|
public ushort Volume { get; set; } = 1;
|
||||||
public string? Issue { get; set; } = null;
|
public byte? Issue { get; set; } = null;
|
||||||
|
public ushort FirstPage { get; set; } = 1;
|
||||||
|
public ushort LastPage { get; set; } = 1;
|
||||||
public string Doi { get; set; } = "";
|
public string Doi { get; set; } = "";
|
||||||
public string Url { get; set; } = "";
|
public string Url { get; set; } = "";
|
||||||
|
|
||||||
public string Convert(string[] entryLines)
|
public string Convert(string[] entryLines)
|
||||||
{
|
{
|
||||||
var checkVol = (string v) =>
|
var temp = entryLines[1].Split(',');
|
||||||
v.Split(',').Length == 2 ? v.Split(',')[0].Trim() : v.Trim();
|
var rearrange = (string a) =>
|
||||||
|
{
|
||||||
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
a = a.Trim();
|
||||||
|
var s = a.Split(' ');
|
||||||
|
return $"{s[1]} {s[0]}";
|
||||||
|
};
|
||||||
|
Author = temp.Select(a => rearrange(a)).ToArray();
|
||||||
Year = ushort.Parse(entryLines[2]);
|
Year = ushort.Parse(entryLines[2]);
|
||||||
Title = entryLines[3];
|
Title = entryLines[3];
|
||||||
Journal = entryLines[4];
|
Journal = entryLines[4];
|
||||||
Volume = entryLines[5] != string.Empty ? checkVol(entryLines[5]) : Volume;
|
Volume = entryLines[5].Split(',').Length == 2 ?
|
||||||
|
byte.Parse(entryLines[5].Split(',')[0]) :
|
||||||
|
byte.Parse(entryLines[5]);
|
||||||
Issue = entryLines[5].Split(',').Length == 2 ?
|
Issue = entryLines[5].Split(',').Length == 2 ?
|
||||||
entryLines[5].Split(',')[1].Trim() : Issue;
|
byte.Parse(entryLines[5].Split(',')[1]) : null;
|
||||||
Pages = CreatePages(entryLines[6]);
|
FirstPage = ushort.Parse(entryLines[6].Split('-')[0]);
|
||||||
|
LastPage = ushort.Parse(entryLines[6].Split('-')[1]);
|
||||||
if (entryLines.Length > 7 )
|
Doi = entryLines.Length > 7 ? entryLines[7] : "";
|
||||||
{
|
|
||||||
if (IsDoi(entryLines[7])) Doi = entryLines[7];
|
|
||||||
else Url = entryLines[7];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToString();
|
return ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"@{Type}{{{Author[0][..2].Replace(". ", "_")}_{Year},\n" +
|
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
|
||||||
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
|
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
|
||||||
$"\ttitle = {{{Title}}},\n" +
|
$"\ttitle = {{{Title}}},\n" +
|
||||||
$"\tjournal = \"{Journal}\",\n" +
|
$"\tjournal = \"{Journal}\",\n" +
|
||||||
$"\tyear = \"{Year}\",\n" +
|
$"\tyear = \"{Year}\",\n" +
|
||||||
$"\tvolume = \"{Volume}\",\n" +
|
$"\tvolume = \"{Volume}\",\n" +
|
||||||
$"\tnumber = \"{Issue}\",\n" +
|
$"\tnumber = \"{Issue}\",\n" +
|
||||||
$"\tpages = \"{Pages}\",\n" +
|
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
|
||||||
$"\tdoi = \"{Doi}\",\n" +
|
$"\tdoi = \"{Doi}\",\n" +
|
||||||
$"\turl = \"{Url}\",\n" +
|
$"\turl = \"{Url}\",\n" +
|
||||||
"}\n";
|
"}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record class Book : ItemType, IBib
|
public record class BookBib : IBib
|
||||||
{
|
{
|
||||||
public string Type { get; init; } = "book";
|
public string Type { get; init; } = "book";
|
||||||
public string[] Author { get; set; } = Array.Empty<string>();
|
public string[] Author { get; set; } = { "Gianni e Pinotto" };
|
||||||
public string[] Editor { get; set; } = Array.Empty<string>();
|
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
public ushort Year { get; set; } = 1950;
|
|
||||||
public string Publisher { get; set; } = "";
|
public string Publisher { get; set; } = "";
|
||||||
public string Series { get; set; } = "";
|
|
||||||
public string Place { get; set; } = "";
|
public string Place { get; set; } = "";
|
||||||
public string Url { get; set; } = "";
|
public string Url { get; set; } = "";
|
||||||
public string Doi { get; set; } = "";
|
public ushort Year { get; set; } = 1950;
|
||||||
|
|
||||||
public string Convert(string[] entryLines)
|
|
||||||
{
|
|
||||||
var auths = entryLines[1];
|
|
||||||
if (auths.Contains("ed"))
|
|
||||||
{
|
|
||||||
Editor = Regex.Replace(auths,@"\(eds?\.\)", "").Split(',').Select(a => Rearrange(a)).ToArray();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Author = auths.Split(',').Select(a => Rearrange(a)).ToArray();
|
|
||||||
}
|
|
||||||
Year = ushort.Parse(entryLines[2]);
|
|
||||||
Title = entryLines[3];
|
|
||||||
Series = entryLines[4] != string.Empty ? entryLines[4] : Series;
|
|
||||||
Place = entryLines[5];
|
|
||||||
Publisher = entryLines[6];
|
|
||||||
|
|
||||||
if (entryLines.Length > 7 )
|
|
||||||
{
|
|
||||||
if (IsDoi(entryLines[7])) Doi = entryLines[7];
|
|
||||||
else Url = entryLines[7];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string label;
|
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
|
||||||
string authString;
|
$"\tauthor = \"{string.Join(" and", Author)}\",\n" +
|
||||||
|
|
||||||
if (Author.Length != 0)
|
|
||||||
{
|
|
||||||
label = Author[0][..2].Replace(". ", "");
|
|
||||||
authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
label = Editor[0][..2].Replace(". ", "");
|
|
||||||
authString = $"\teditor = \"{string.Join(" and ", Editor)}\",\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"@{Type}{{{label}_{Year},\n" +
|
|
||||||
authString +
|
|
||||||
$"\ttitle = {{{Title}}},\n" +
|
$"\ttitle = {{{Title}}},\n" +
|
||||||
$"\tpublisher = \"{Publisher}\",\n" +
|
$"\tpublisher = \"{Publisher}\",\n" +
|
||||||
$"\tseries = \"{Series}\",\n" +
|
|
||||||
$"\taddress = \"{Place}\",\n" +
|
$"\taddress = \"{Place}\",\n" +
|
||||||
$"\tyear = \"{Year}\",\n" +
|
$"\tyear = \"{Year}\",\n" +
|
||||||
$"\turl = \"{Url}\",\n" +
|
$"\turl = \"{Url}\",\n" +
|
||||||
$"\tdoi = \"{Doi}\",\n" +
|
|
||||||
"}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record class Proceedings : ItemType, IBib
|
|
||||||
{
|
|
||||||
public string Type { get; init; } = "inproceedings";
|
|
||||||
public string[] Author { get; set; } = Array.Empty<string>();
|
|
||||||
public string[] Editor { get; set; } = Array.Empty<string>();
|
|
||||||
public string Title { get; set; } = "";
|
|
||||||
public string BookTitle { get; set; } = "";
|
|
||||||
public ushort Year { get; set; } = 1950;
|
|
||||||
public string Publisher { get; set; } = "";
|
|
||||||
public string Series { get; set; } = "";
|
|
||||||
public string Address { get; set; } = "";
|
|
||||||
public string Url { get; set; } = "";
|
|
||||||
public string Doi { get; set; } = "";
|
|
||||||
|
|
||||||
public string Convert(string[] entryLines)
|
|
||||||
{
|
|
||||||
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
|
||||||
Year = ushort.Parse(entryLines[2]);
|
|
||||||
Title = entryLines[3];
|
|
||||||
Editor = entryLines[4] != String.Empty ?
|
|
||||||
Regex.Replace(entryLines[4], @"\(eds?\.\)", "").Split(',').Select(a => Rearrange(a)).ToArray() :
|
|
||||||
Editor;
|
|
||||||
BookTitle = entryLines[5];
|
|
||||||
Series = entryLines[6] != String.Empty ? entryLines[6] : Series;
|
|
||||||
Address = entryLines[7] != String.Empty ? entryLines[7] : Address;
|
|
||||||
Publisher = entryLines[8];
|
|
||||||
Pages = CreatePages(entryLines[9]);
|
|
||||||
|
|
||||||
if (entryLines.Length > 10)
|
|
||||||
{
|
|
||||||
if (IsDoi(entryLines[10])) Doi = entryLines[10];
|
|
||||||
else Url = entryLines[10];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
string label = Author[0][..2].Replace(". ", "");
|
|
||||||
string authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n";
|
|
||||||
string edsString = Editor.Length != 0 ?
|
|
||||||
$"\teditor = \"{string.Join(" and ", Editor)}\",\n" : "";
|
|
||||||
|
|
||||||
return $"@{Type}{{{label}_{Year},\n" +
|
|
||||||
authString +
|
|
||||||
edsString +
|
|
||||||
$"\ttitle = {{{Title}}},\n" +
|
|
||||||
$"\tbooktitle = {{{BookTitle}}},\n" +
|
|
||||||
$"\tpublisher = \"{Publisher}\",\n" +
|
|
||||||
$"\tseries = {{{Series}}},\n" +
|
|
||||||
$"\taddress = \"{Address}\",\n" +
|
|
||||||
$"\tyear = \"{Year}\",\n" +
|
|
||||||
$"\tpages = \"{Pages}\",\n" +
|
|
||||||
$"\turl = \"{Url}\",\n" +
|
|
||||||
$"\tdoi = \"{Doi}\",\n" +
|
|
||||||
"}\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public record class Chapter : ItemType, IBib
|
|
||||||
{
|
|
||||||
public string Type { get; init; } = "incollection";
|
|
||||||
public string[] Author { get; set; } = Array.Empty<string>();
|
|
||||||
public string[] Editor { get; set; } = Array.Empty<string>();
|
|
||||||
public string Title { get; set; } = "";
|
|
||||||
public string BookTitle { get; set; } = "";
|
|
||||||
public ushort Year { get; set; } = 1950;
|
|
||||||
public string Publisher { get; set; } = "";
|
|
||||||
public string Series { get; set; } = "";
|
|
||||||
public string Address { get; set; } = "";
|
|
||||||
public string Url { get; set; } = "";
|
|
||||||
public string Doi { get; set; } = "";
|
|
||||||
|
|
||||||
public string Convert(string[] entryLines)
|
|
||||||
{
|
|
||||||
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
|
|
||||||
Year = ushort.Parse(entryLines[2]);
|
|
||||||
Title = entryLines[3];
|
|
||||||
Editor = Regex.Replace(entryLines[4], @"\(eds?\.\)", "").Split(',').Select(a => Rearrange(a)).ToArray();
|
|
||||||
BookTitle = entryLines[5];
|
|
||||||
Series = entryLines[6] != String.Empty ? entryLines[6] : Series;
|
|
||||||
Address = entryLines[7] != String.Empty ? entryLines[7] : Address;
|
|
||||||
Publisher = entryLines[8];
|
|
||||||
Pages = CreatePages(entryLines[9]);
|
|
||||||
|
|
||||||
if (entryLines.Length > 10)
|
|
||||||
{
|
|
||||||
if (IsDoi(entryLines[10])) Doi = entryLines[10];
|
|
||||||
else Url = entryLines[10];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
string label = Author[0][..2].Replace(". ", "");
|
|
||||||
string authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n";
|
|
||||||
string edsString = $"\teditor = \"{string.Join(" and ", Editor)}\",\n";
|
|
||||||
|
|
||||||
return $"@{Type}{{{label}_{Year},\n" +
|
|
||||||
authString +
|
|
||||||
edsString +
|
|
||||||
$"\ttitle = {{{Title}}},\n" +
|
|
||||||
$"\tbooktitle = {{{BookTitle}}},\n" +
|
|
||||||
$"\tpublisher = \"{Publisher}\",\n" +
|
|
||||||
$"\tseries = {{{Series}}},\n" +
|
|
||||||
$"\taddress = \"{Address}\",\n" +
|
|
||||||
$"\tyear = \"{Year}\",\n" +
|
|
||||||
$"\tpages = \"{Pages}\",\n" +
|
|
||||||
$"\turl = \"{Url}\",\n" +
|
|
||||||
$"\tdoi = \"{Doi}\",\n" +
|
|
||||||
"}\n";
|
"}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
58
Text2Bib.cs
58
Text2Bib.cs
@ -15,8 +15,7 @@ namespace Txt2Bib
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Text2Bib
|
public class Text2Bib
|
||||||
{
|
{
|
||||||
private readonly string[] _citTypes = { "J", "B", "C", "P", "PB" };
|
private string[] _citTypes = { "J", "B", "C", "P", "?" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate single .bib file from input text files
|
/// Generate single .bib file from input text files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -25,44 +24,33 @@ namespace Txt2Bib
|
|||||||
public string Generate(string filenames)
|
public string Generate(string filenames)
|
||||||
{
|
{
|
||||||
var paths = filenames.Trim().Split('\n');
|
var paths = filenames.Trim().Split('\n');
|
||||||
var output = "";
|
string result = "";
|
||||||
|
string output = "";
|
||||||
|
|
||||||
foreach (var path in paths)
|
foreach (var path in paths)
|
||||||
{
|
{
|
||||||
output += CreateBibTeX(path);
|
var reader = File.OpenText(path);
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Create a BibTeX string from an input file path
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string CreateBibTeX(string path)
|
|
||||||
{
|
|
||||||
using var reader = File.OpenText(path);
|
|
||||||
byte[] contentBytes = File.ReadAllBytes(path);
|
byte[] contentBytes = File.ReadAllBytes(path);
|
||||||
// Assumes UTF8!
|
|
||||||
var content = Encoding.UTF8.GetString(contentBytes);
|
result += Encoding.Latin1.GetString(contentBytes);
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerable<string> entries = new List<string>();
|
IEnumerable<string> entries = new List<string>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
entries = content.Split('%').ToList().Select(entry => Process(entry));
|
entries = result.Split('%').ToList().Select(entry => Process(entry));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
throw new Exception($"Errore di elaborazione in {entries.Last()}");
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bibtex = "";
|
|
||||||
foreach (var entry in entries)
|
foreach (var entry in entries)
|
||||||
{
|
{
|
||||||
bibtex += entry;
|
output += entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bibtex;
|
return output;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a bib entry from source text
|
/// Creates a bib entry from source text
|
||||||
@ -76,25 +64,16 @@ namespace Txt2Bib
|
|||||||
var lines = entryFromTxt.Trim().Replace("\r", string.Empty).Split("\n");
|
var lines = entryFromTxt.Trim().Replace("\r", string.Empty).Split("\n");
|
||||||
var type = lines.First().Trim();
|
var type = lines.First().Trim();
|
||||||
|
|
||||||
//if (!IsValidEntry(type)) throw new Exception($"Invalid entry type '{type}'");
|
if (!IsValidEntry(type)) throw new Exception($"Invalid entry type '{type}'");
|
||||||
|
|
||||||
string citation;
|
string citation = type switch
|
||||||
try
|
|
||||||
{
|
{
|
||||||
citation = type switch
|
"J" => (new ArticleBib()).Convert(lines),
|
||||||
{
|
//"B" => new BookBib(),
|
||||||
"J" => new Article().Convert(lines),
|
//"C" => new ChapterBib(),
|
||||||
"B" => new Book().Convert(lines),
|
//"P" => new ConferenceBib(),
|
||||||
"PB" => new Book().Convert(lines),
|
_ => (new ArticleBib()).Convert(lines)
|
||||||
"C" => new Chapter().Convert(lines),
|
|
||||||
"P" => new Proceedings().Convert(lines),
|
|
||||||
_ => ""
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception($"Errore in {entryFromTxt}\nMessaggio di errore: \"{ex.Message}\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
return citation;
|
return citation;
|
||||||
}
|
}
|
||||||
@ -116,6 +95,7 @@ namespace Txt2Bib
|
|||||||
{
|
{
|
||||||
var cp = "UTF-8";
|
var cp = "UTF-8";
|
||||||
return Encoding.GetEncoding(cp);
|
return Encoding.GetEncoding(cp);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,20 +5,15 @@
|
|||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<Version>0.2.0</Version>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="aec_icon.png" />
|
|
||||||
<None Remove="copy-icon.png" />
|
<None Remove="copy-icon.png" />
|
||||||
<None Remove="menu-1768000-1502336.png" />
|
|
||||||
<None Remove="openfolder_4896.png" />
|
<None Remove="openfolder_4896.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="aec_icon.png" />
|
|
||||||
<Resource Include="copy-icon.png" />
|
<Resource Include="copy-icon.png" />
|
||||||
<Resource Include="menu-1768000-1502336.png" />
|
|
||||||
<Resource Include="openfolder_4896.png" />
|
<Resource Include="openfolder_4896.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
BIN
aec_icon.png
BIN
aec_icon.png
Binary file not shown.
Before Width: | Height: | Size: 32 KiB |
9
docfx_project/.gitignore
vendored
9
docfx_project/.gitignore
vendored
@ -1,9 +0,0 @@
|
|||||||
###############
|
|
||||||
# folder #
|
|
||||||
###############
|
|
||||||
/**/DROP/
|
|
||||||
/**/TEMP/
|
|
||||||
/**/packages/
|
|
||||||
/**/bin/
|
|
||||||
/**/obj/
|
|
||||||
_site
|
|
5
docfx_project/api/.gitignore
vendored
5
docfx_project/api/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
###############
|
|
||||||
# temp file #
|
|
||||||
###############
|
|
||||||
*.yml
|
|
||||||
.manifest
|
|
@ -1,2 +0,0 @@
|
|||||||
# PLACEHOLDER
|
|
||||||
TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*!
|
|
@ -1 +0,0 @@
|
|||||||
# Add your introductions here!
|
|
@ -1,2 +0,0 @@
|
|||||||
- name: Introduction
|
|
||||||
href: intro.md
|
|
@ -1,65 +0,0 @@
|
|||||||
{
|
|
||||||
"metadata": [
|
|
||||||
{
|
|
||||||
"src": [
|
|
||||||
{
|
|
||||||
"files": [
|
|
||||||
"*.csproj"
|
|
||||||
],
|
|
||||||
"src" : "../"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dest": "api",
|
|
||||||
"disableGitFeatures": true,
|
|
||||||
"disableDefaultFilter": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"build": {
|
|
||||||
"content": [
|
|
||||||
{
|
|
||||||
"files": [
|
|
||||||
"api/**.yml",
|
|
||||||
"api/index.md"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"files": [
|
|
||||||
"articles/**.md",
|
|
||||||
"articles/**/toc.yml",
|
|
||||||
"toc.yml",
|
|
||||||
"*.md"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"resource": [
|
|
||||||
{
|
|
||||||
"files": [
|
|
||||||
"images/**"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"overwrite": [
|
|
||||||
{
|
|
||||||
"files": [
|
|
||||||
"apidoc/**.md"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"obj/**",
|
|
||||||
"_site/**"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"dest": "_site",
|
|
||||||
"globalMetadataFiles": [],
|
|
||||||
"fileMetadataFiles": [],
|
|
||||||
"template": [
|
|
||||||
"modern"
|
|
||||||
],
|
|
||||||
"postProcessors": [],
|
|
||||||
"markdownEngineName": "markdig",
|
|
||||||
"noLangKeyword": false,
|
|
||||||
"keepFileLink": false,
|
|
||||||
"cleanupCacheHistory": false,
|
|
||||||
"disableGitFeatures": false
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
# This is the **HOMEPAGE**.
|
|
||||||
Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files.
|
|
||||||
## Quick Start Notes:
|
|
||||||
1. Add images to the *images* folder if the file is referencing an image.
|
|
@ -1,5 +0,0 @@
|
|||||||
- name: Articles
|
|
||||||
href: articles/
|
|
||||||
- name: Api Documentation
|
|
||||||
href: api/
|
|
||||||
homepage: api/index.md
|
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB |
BIN
info-icon.png
BIN
info-icon.png
Binary file not shown.
Before Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.0 KiB |
Loading…
Reference in New Issue
Block a user