Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
M README.md
6868
* Platform-independent (Windows, Linux, MacOS)
6969
70
## Typesetting
71
72
Typesetting to PDF files requires the following:
73
74
* [Theme Pack](https://github.com/DaveJarvis/keenwrite-themes/releases/latest/download/theme-pack.zip)
75
* [ConTeXt](https://wiki.contextgarden.net/Installation)
76
7077
## Usage
7178
M README.zh-CN.md
5050
* 嵌入R语句
5151
52
## Typesetting
53
54
排版到 PDF 文件需要以下內容:
55
56
* [Theme Pack](https://github.com/DaveJarvis/keenwrite-themes/releases/latest/download/theme-pack.zip)
57
* [ConTeXt](https://wiki.contextgarden.net/Installation)
58
5259
## 软件使用
5360
54
See the [detailed documentation](docs/README.md) for information about
55
using the application.
61
有關使用該應用程序的信息,請參[閱詳細文檔](docs/README.md)。
5662
5763
## 截图
M src/main/java/com/keenwrite/processors/markdown/extensions/fences/FencedBlockExtension.java
3636
 */
3737
public final class FencedBlockExtension extends HtmlRendererAdapter {
38
  private final static String TEMP_DIR = System.getProperty( "java.io.tmpdir" );
39
40
  /**
41
   * Ensure that the device is always closed to prevent an out-of-resources
42
   * error, regardless of whether the R expression the user tries to evaluate
43
   * is valid by swallowing errors alongside a {@code finally} block.
44
   */
45
  private final static String R_SVG_EXPORT =
46
    "tryCatch({svg('%s')%n%s%n},finally={dev.off()})%n";
47
3848
  private final static String STYLE_DIAGRAM = "diagram-";
3949
  private final static int STYLE_DIAGRAM_LEN = STYLE_DIAGRAM.length();
...
178188
      final var text = mRVariableProcessor.apply( content );
179189
      final var hash = Integer.toHexString( text.hashCode() );
180
      final var temp = System.getProperty( "java.io.tmpdir" );
181
      final var file = format( "%s-%s.svg", APP_TITLE_LOWERCASE, hash );
182
      final var source = Paths.get( temp, file ).toString();
183
      final var link = context.resolveLink( LINK, source, false );
184
      final var r = format( "svg('%s')%n%s%ndev.off()%n", source, text );
190
      final var filename = format( "%s-%s.svg", APP_TITLE_LOWERCASE, hash );
191
      final var svg = Paths.get( TEMP_DIR, filename ).toString();
192
      final var link = context.resolveLink( LINK, svg, false );
193
      final var r = format( R_SVG_EXPORT, svg, text );
185194
      final var result = mRChunkEvaluator.apply( r );
186195
187
      return new Pair<>( source, link );
196
      return new Pair<>( svg, link );
188197
    }
189198
A src/test/java/com/keenwrite/io/FileObjectTest.java
1
package com.keenwrite.io;
2
3
import org.apache.commons.vfs2.FileSystemException;
4
import org.junit.jupiter.api.Disabled;
5
import org.renjin.eval.SessionBuilder;
6
7
import java.io.IOException;
8
import java.io.OutputStreamWriter;
9
10
import static java.io.File.separator;
11
import static java.lang.String.format;
12
import static java.nio.charset.StandardCharsets.UTF_8;
13
14
/**
15
 * Tests file resource allocation.
16
 */
17
public class FileObjectTest {
18
  private final static String TEMP_DIR = System.getProperty( "java.io.tmpdir" );
19
20
  /**
21
   * Test that resources are not exhausted.
22
   *
23
   * Disabled because no issue was found and this test thrashes the I/O.
24
   */
25
  @Disabled
26
  void test_Open_MultipleFiles_NoResourcesExpire() throws FileSystemException {
27
    final var builder = new SessionBuilder();
28
    final var session = builder.build();
29
30
    for( int i = 0; i < 10000; i++ ) {
31
      final var filename = format( "%s%s%d.txt", TEMP_DIR, separator, i );
32
      final var fileObject = session
33
        .getFileSystemManager()
34
        .resolveFile( filename );
35
36
      try(
37
        final var stream = fileObject.getContent().getOutputStream();
38
        final var writer = new OutputStreamWriter( stream, UTF_8 ) ) {
39
        writer.write( "contents" );
40
      } catch( final IOException e ) {
41
        throw new FileSystemException( e );
42
      }
43
44
      fileObject.delete();
45
    }
46
  }
47
}
148