Exemplo n.º 1
0
        /// <summary>
        /// Convert references as used in introductory outlines. A typical example would be "1. Wniak kalwieda. (1:1-2)"
        /// We want the output to be 1. Wniak kalwieda. <a href="#C1V1>(1:1-2)</a>.
        /// </summary>
        /// <param name="chunk"></param>
        /// <returns></returns>
        private string ConvertOutlineRefs(string chunk, string baseFileName, bool hasNoChapters)
        {
            // Looks for parenthesized expression containing (verse) number, or C:V, possibly followed by
            // a range indication. We don't care much about the range, so once we have C:V if that can be found,
            // we accept any combination of digits, colon, and hyphen
            Regex reRef = new Regex(@"\(([0-9]+)(:[0-9]+)?(-[0-9: ]+)?\)");
            Match match = reRef.Match(chunk);

            if (!match.Success)
            {
                return(chunk);
            }
            StringBuilder output = new StringBuilder(chunk.Length + 40);
            string        chap   = "1";
            string        verse  = match.Groups[1].Value;

            if (match.Groups.Count > 2 && match.Groups[2].Length > 0)
            {
                chap  = verse;
                verse = match.Groups[2].Value.Substring(1);                 // strip colon
            }
            else if (!hasNoChapters)
            {
                // A single number in a book with chapters is interpreted as a chapter number
                chap  = verse;
                verse = "1";
            }
            string destFileName = baseFileName;

            if (m_options.ChapterPerFile)
            {
                // If the book has no chapters, we will combine it with its TOC in a single file so we need to give that file
                // name for the destination rather than one based on the chapter number.
                string fileTag = chap;
                if (hasNoChapters)
                {
                    fileTag = ChapterSplitter.tocTag;
                }
                destFileName = ChapterSplitter.MakeNameForSegment(destFileName, fileTag);
            }
            destFileName = Path.ChangeExtension(destFileName, "htm");

            InsertHotLink(output, chunk, match, match.Index, destFileName + "#C" + chap + "V" + verse);

            return(output.ToString());
        }
Exemplo n.º 2
0
        internal override void DoPostProcessing(string outputFileName, string outputFilePath)
        {
            string input = ReadFileToString(outputFilePath);

            if (input == null)
            {
                ReportError("Could not do postprocessing because xslt produced no output");
                return;                 // couldn't complete initial stages?
            }
            input = MoveAnchorsBeforeHeadings(input);
            input = CreateSymbolCrossRefs(input);
            string stage2 = FixDuplicateAnchors(input);

            MakeCrossRefLinkInfo(stage2, outputFilePath);

            if (m_options.ChapterPerFile)
            {
                string message = new ChapterSplitter(outputFilePath, m_options, m_pageFooter).Run(ref m_prevFile, m_nextFiles[outputFileName],
                                                                                                  this);
                if (message == null)
                {
                    File.Delete(outputFilePath);
                    foreach (string itemPath in Utils.ChapFiles(outputFilePath))
                    {
                        File.Copy(itemPath, Path.Combine(m_finalOutputDir, Path.GetFileName(itemPath)), true);
                    }
                    return;
                }
                else
                {
                    MessageBox.Show("Could not split " + outputFilePath + " - " + message, "Error");                     // Enhance: provide more info.
                }
            }

            // And copy to the main output directory
            if (m_finalOutputDir != null)
            {
                File.Copy(outputFilePath, Path.Combine(m_finalOutputDir, outputFileName), true);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Run the algorithm (on all files).
        /// </summary>
        public void Run(IList files)
        {
            Utils.EnsureDirectory(m_outputDirName);
            m_xslt.Load(Utils.GetUtilityFile("osis2ChapIndexFrag.xsl"));

            string header = "<!doctype HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n<html>\n"
                            + "<link rel=\"stylesheet\" href=\"display.css\" type=\"text/css\">"
                            + "<head>"
                            + "</head>\n<body class=\"BookChapIndex\">\n"
                            + "<p><a target=\"body\" href=\"treeMaster.htm\">" + m_options.ConcordanceLinkText + "</a></p>\n";
            string bcHeaderPath = Path.Combine(Path.GetDirectoryName(m_inputDirName), "bookChapterHeader.txt");

            if (File.Exists(bcHeaderPath))
            {
                string headerFmt = new StreamReader(bcHeaderPath, Encoding.UTF8).ReadToEnd();
                header = string.Format(headerFmt, m_options.ConcordanceLinkText);
            }
            string trailer = "</body>\n</html>\n";

            string bcFooterPath = Path.Combine(Path.GetDirectoryName(m_inputDirName), "bookChapterFooter.txt");

            if (File.Exists(bcFooterPath))
            {
                string trailerFmt = new StreamReader(bcFooterPath, Encoding.UTF8).ReadToEnd();
                trailer = string.Format(trailerFmt, m_options.ConcordanceLinkText);
            }
            string     path   = Path.Combine(m_outputDirName, "ChapterIndex.htm");
            TextWriter writer = new StreamWriter(path, false, Encoding.UTF8);

            writer.Write(header);

            Progress status = new Progress(files.Count);

            status.Show();
            int count = 0;

            foreach (string inputFile in m_options.MainFiles)
            {
                string filename = Path.GetFileName(inputFile);
                if (files.Contains(Path.ChangeExtension(filename, "xml")))
                {
                    status.File = filename;
                    string       inputFilePath = Path.Combine(m_inputDirName, inputFile);
                    MemoryStream output        = new MemoryStream();

                    TextReader inputReader = new StreamReader(inputFilePath, Encoding.UTF8);
                    XmlReader  input       = XmlReader.Create(inputReader);
                    m_xslt.Transform(input, new XsltArgumentList(), output);
                    output.Seek(0, SeekOrigin.Begin);
                    StreamReader reader   = new StreamReader(output, Encoding.UTF8);
                    string       fragment = reader.ReadToEnd();
                    string       htmlFile = Path.ChangeExtension(inputFile, "htm");
                    if (m_options.ChapterPerFile)
                    {
                        htmlFile = ChapterSplitter.BuildNextFileLinkTargetName(htmlFile);
                    }
                    fragment = fragment.Replace("$$filename$$", htmlFile);
                    fragment = fragment.Replace(" xmlns:osis=\"http://www.bibletechnologies.net/2003/OSIS/namespace\"", "");

                    // Handle introduction if any
                    string introCrossRef = "";
                    string introFile;
                    string introPath = null;
                    if (m_options.IntroFiles.TryGetValue(inputFile, out introFile))
                    {
                        introPath = Path.Combine(m_introDirName, introFile);
                        if (File.Exists(introPath))
                        {
                            File.Copy(introPath, Path.Combine(m_outputDirName, introFile), true);
                        }
                        else
                        {
                            MessageBox.Show("Introduction file not found: " + introPath, "Warning", MessageBoxButtons.OK,
                                            MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        // See if we generated one
                        introPath = Path.Combine(m_outputDirName, OSIS_to_HTML.MakeIntroFileName(filename));
                        if (File.Exists(introPath))
                        {
                            introFile = Path.GetFileName(introPath);
                        }
                        else
                        {
                            introPath = null;
                        }
                    }

                    if (introPath != null)
                    {
                        introCrossRef = "<p class=\"IndexIntroduction\"><a target=\"main\" href=\"" + introFile + "\">" +
                                        m_options.IntroductionLinkText + "</a></p>";
                    }

                    fragment = fragment.Replace("$$intro$$", introCrossRef);
                    if (m_options.ChapterPerFile)
                    {
                        fragment = FixChapterHrefs(fragment);
                    }
                    writer.WriteLine(fragment);
                    count++;
                    status.Value = count;
                }
            }
            if (m_options.ExtraFiles != null)
            {
                foreach (ExtraFileInfo efi in m_options.ExtraFiles)
                {
                    string fileName = efi.FileName;
                    string linkText = efi.HotLinkText;
                    string filePath = Path.Combine(m_extraDirName, fileName);
                    if (!File.Exists(filePath))
                    {
                        MessageBox.Show(String.Format("File {0} requested as link but not found.", filePath), "Warning");
                        continue;
                    }

                    writer.Write("<p class=\"extraLink\"><a target=\"main\" href=\""
                                 + fileName + "\">" + linkText + "</a></p>\n");
                    File.Copy(filePath, Path.Combine(m_outputDirName, fileName), true);
                }
            }
            writer.Write(trailer);
            writer.Close();

            status.Close();
        }